https://github.com/net2devcrypto/pinata-ipfs-nextjs-functions
Simple Pinata IPFS Functions for Next JS to Upload Files and JSON.
https://github.com/net2devcrypto/pinata-ipfs-nextjs-functions
Last synced: 6 days ago
JSON representation
Simple Pinata IPFS Functions for Next JS to Upload Files and JSON.
- Host: GitHub
- URL: https://github.com/net2devcrypto/pinata-ipfs-nextjs-functions
- Owner: net2devcrypto
- Created: 2023-01-24T05:53:07.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-24T06:02:06.000Z (about 3 years ago)
- Last Synced: 2025-01-29T21:43:32.300Z (about 1 year ago)
- Size: 4.88 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pinata-IPFS-NextJS-Functions
Simple Pinata IPFS Functions for Next JS to Upload Files.
Use in your NextJS App:
Dependencies:
```shell
npm i axios
```
UPLOAD FILES TO IPFS Using PINATA:
// Replace key and secret with your Pinata api key and api secret.
FUNCTION:
```shell
async function sendFileToIPFS (e) {
const file = e.target.files[0];
const formData = new FormData();
formData.append("file", file);
const key = 'Your Pinata Api Key';
const secret = 'Your Pinata Api Secret Key'
const url = "https://api.pinata.cloud/pinning/pinFileToIPFS"
const opts = JSON.stringify({
cidVersion: 0,
})
formData.append('pinataOptions', opts);
const options = {
maxBodyLength: "Infinity",
headers: {
'Content-Type': `multipart/form-data; boundary=${formData._boundary}`,
pinata_api_key: key,
pinata_secret_api_key: secret,
Accept: 'text/plain',
}
}
const resFile = await axios.post(url, formData, options);
const ImgHash = `ipfs://${resFile.data.IpfsHash}`;
console.log(ImgHash);
}
```
Attach to your html upload button :
```shell
```