I am trying to upload the metadata(JavaScript Object) of a file already uploaded to IPFS, from the client side in the NextJS. I am able to upload files(PDFs) to IPFS using the Infura's HTTP API with the help of the ipfs-http-client package, but I am not able to do so with JSON?
I have also tried uploading using the pinata SDK but in vain.
How can I upload the JavaScript object to IPFS?
How can I upload a json file (or JavaScript Object) to IPFS in NextJS?
2.7k views Asked by saditya At
2
There are 2 answers
1
Yilmaz
On
You can use pinata-api without third party library
from the client you send the metadata to the server and the server sends post a request to pinata.
const url = `https://api.pinata.cloud/pinning/pinJSONToIPFS`;
const res = await axios.post(
url,
{
pinataMetadata: {
name: "add a name",
},
// assuming client sends `nftMeta` json
pinataContent: req.body.nftMeta,
},
{
headers: {
pinata_api_key: yourPinataApiKey,
pinata_secret_api_key: yourPinataSecretApiKey,
},
}
);
Related Questions in JAVASCRIPT
- Using Puppeteer to scrape a public API only when the data changes
- inline SVG text (js)
- An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
- Storing the preferred font-size in localStorage
- Simple movie API request not showing up in the console log
- Authenticate Flask rest API
- Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
- How to request administrator rights?
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- In Datatables, start value resets to 0, when column sorting
- How do I link two models in mongoose?
- parameter values only being sent to certain columns in google sheet?
- Run main several times of wasm in browser
- Variable inside a Variable, not updating
Related Questions in BLOCKCHAIN
- Sepolia test network ID
- Gas Estimation Fee on Tron Mainnet
- This is the solidity code to list nft in marketplace after minting but while calling makeItem function Error is showing that Faliled to estimate gas
- Trying to send transactions via a signer using my private key
- My question is regarding installation of a package in VS code but im getting an error in installing it
- Historical data scrapping / collection for Ethereum
- Installation Private Blockchain
- How to import rpc information without importing .env file or hardcoding on frontend?
- How do I speed up transaction filtering on solan blockchain?
- Undeclared identifier: VRF_V2_Wrapper.calculateRequestPrice()
- how to interpret and format iterest rates and index returned by aave event
- Can I swap with 1inch swap apis with forked hardhart?
- How to connect metamask to flutter mobile app
- Scraping 'offers' data from OpenSea
- Which web3 decentralized wallet is suitable to store my crypto assets and lock some of the tokens for certain time?
Related Questions in IPFS
- WebTransportError in firefox
- Can I build a dynamic Web3 site using IPFS?
- In IPFS, will same content produce the same CID on 2 different peers?
- My NFT token Metadata is not opened by Opensea
- How to pin an object (as opposed to a file) to and IPFS node?
- How do I include an already existing web3 directory in a new directory without reuploading it
- I am trying to implement a python3 library to create IPFS-Merkle DAGs but I have been unable to figure out the correct way to specify links?
- Hugo generated site is not deploying correctly, what am I doing wrong?
- NextAuth and IPFS error when hosting on app.fleek.co
- How to setup ipfs on node or in anular app using aws ec2 instance kubo setup
- IPFS not announcing CIDs on indirect peers and unable to get through cmd as CID is not propagated using DHT
- IPFS RPC API : ipfs routing findprovs provides an unreadable response
- WebSocket connection Failed when using Helia IPFS in react app
- IPNS, ENS, content hash records
- ipfs - I just cannot get it working reliably
Related Questions in IPFS-HTTP-CLIENT
- How to pin an object (as opposed to a file) to and IPFS node?
- Error: "Cannot find module './fetch.node'" when using ipfs with Next.js 14 on Vercel
- Connecting Html to IPFS and upload a file
- How to access the Infura IPFS api in angular
- IPFS: HTTPError: URL arg must be multibase encoded: selected encoding not supported
- How to Add Data to IPFS through Smart Contract in Truffle?
- Module not found: Can't resolve 'ipfs-http-client' in '/home/ubuntu/chatapp/src/components'
- Infura client IPFS configuration, image upload, request error
- How to solve this CORS error where I am trying to push files to IPFS using infura
- ipfs-http-client cat sometimes return incomplete file
- Access to XMLHttpRequest has been blocked by CORS policy:
- Cannot connect to IPFS Error: no protocol with name: quic-v1
- Why IPFS Cluster nodes cannot find each other
- how to get CID of file when creating using ipfs.files.write using ipfs-http-client
- Error when I try to add ipfs file with my nodejs Dapp
Related Questions in PINATA
- Can I build a dynamic Web3 site using IPFS?
- ERR_BAD_REQUEST - Code 400: NFT Marketplace: createNFT function using Pinata not work
- Error Uploading File to IPFS. I am using the pinFileToIPFS gateway
- Error uploading file to IPFS: (readStream is not a readable stream or form data & source.on is not a function)
- POST https://api.pinata.cloud/pinning/pinFileToIPFS 400 while uploading image
- How can I pin json to ipfs with pinata (pinJsonToIpfs method) info directory? React
- Firebase Cloud Function in typescript not working with form data request
- Pinata API Error "Incorrect request. Please send the correct format, { hashToPin: 'yourHash', pinataMetadata: (optional metadata)} For NFTs
- Unable to fetch data from Pinata (IPFS)
- How can I read from S3 and then write to IPFS using Pinata?
- Issue with constructor initialization in Typescript
- After I run "node index.js" instead of a link to the picture, I get only "https://gateway.pinata.cloud/ipfs/${result.IpfsHash}" without IpfsHash
- NextJS: Access to XMLHttpRequest from origin blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource
- Uncaught (in promise) AxiosError {message: 'Request failed with status code 400', name: 'AxiosError', code: 'ERR_BAD_REQUEST
- Running npm run build produces same output
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
The Short Answer: Perform
JSON.stringify()on the JavaScript Object and upload the returned value to the IPFS. You can either use Infura's HTTP API end-point oripfs-http-clientwhich is a client library for the IPFS HTTP API.The Long Answer:
Uploading a file from user's disk:-
1. Using the
ipfs-corepackage:2. Using a public IPFS gateway
Uploading a JavaScript Object as a JSON:-
JSON.stringify(<JS_OBJECT>)and upload the returned value of this function to the IPFS.