I have a blob that I want to store as a value in a JSON: myJson = { myBlob }
on IPFS. I'm working on a node.js app & using Pinata.
This is how I'm uploading the blob to IPFS:
const x = {blob: new Blob(["Hey"])};
console.log(x);
console.log(await x.blob.text());
pinata.pinJSONToIPFS(x).then((result) => {
console.log(result);
}).catch((err) => {
console.log(err);
});
Below is printed in the console:
{ blob: Blob { size: 3, type: '' } }
Hey
{
IpfsHash: 'QmdEhfwmdhBazdHNcYKGAyhrFKwmkRGeWe2fyDBuXXreR3',
PinSize: 19,
Timestamp: '2023-03-09T09:05:28.633Z'
}
Visiting https://gateway.pinata.cloud/ipfs/QmdEhfwmdhBazdHNcYKGAyhrFKwmkRGeWe2fyDBuXXreR3 gives displays: {"blob":{}}
Now I'm retrieving from the above IPFS link:
const res = await fetch('https://gateway.pinata.cloud/ipfs/QmdEhfwmdhBazdHNcYKGAyhrFKwmkRGeWe2fyDBuXXreR3');
console.log(res.body);
const val = await res.json();
console.log(await val.blob);
console.log(await res.blob.text());
The console for the above code snippet:
{ blob: {} }
TypeError: res.blob.text is not a function
But the same works at the top: console.log(await x.blob.text());
.
My question is how can I store a blob on IPFS & retrieve it as a blob? Since I need to pass the same to a different function. Also, I'm using this in a Node.js app so can't use FileReader.