import * as IPFS from 'ipfs-core'
var ipfs = await IPFS.create({ repo: 'ok' + Math.random() })
const metadataMap = new Map()
//content.metadataCid is the ipfs-cid of the metadata.json file stored on ipfs.
var res = await ipfs.cat(content.metadataCid)
//var data = await res.Json()
console.log("** Metadata from Cid **")
console.log(res)
//This just maps the content (content-cid) to its metadata
//sets the metadata for each Content
metadataMap.set(theCid, res)
if (metadataMap) {
console.log('**metadata map**')
console.log(metadataMap)
}
That cid doesn’t resolve for me (I tried my own node, ipfs.io, gateway.pinata.cloud and cf-ipfs.com), so, I think your hosting is the problem, not your code.
Update: my node finally found it after searching for over 30 mins. Once my node had it in its cache, the other places resolved it in seconds. So, I stand by: your hosting isn’t working very well, for some reason
In general if you have json uploaded at a certain CID, you can use the following to retrieve it in JSON format:
// In the imports
import {concat} from 'uint8arrays'
import * as IPFS from 'ipfs-core'
// In the method, assuming you already have created an IPFS instance (await IPFS.create() etc)
for await (const chunk of ipfs.cat(CID)) {
chunks.push(chunk);
}
const data = concat(chunks)
const decodedData = JSON.parse(new TextDecoder().decode(data).toString());
So the decodedData will be your retrieved JSON object.
Apart from the ipfs-core library, you would have to install uint8arrays which you can find here