When I upload PNG images and PDF files using the IPFS library, I’m able to obtain the CIDs. But, when I visit the IPFS URL using theses CIDs, I don’t see the image or the document, but the browser simply prompts me the Save As Download panel. I’m not sure if this is an indication that the files have not been uploaded properly or not and I also don’t know what’s it’s asking me to download.
I’m currently using Brave for the browser and I don’t think it’s the compatibility with the browser because I’m able to view the IPFS files uploaded by others with no issues like the one from the IPFS website.
Following is one of the CIDs I have created:
https://ipfs.io/ipfs/QmNXd16aqe6a353cshxsuM2YaiX9MRAUp1NB5teornHEMV
Following is how I upload images:
const ipfsClient = require("ipfs-http-client");
const ipfs = ipfsClient({
host: "ipfs.infura.io",
port: 5001,
protocol: "https",
});
app.post('/addImage', (req, res, next) => {
var form = new multiparty.Form();
form.parse(req, async function(err, fields, files) {
const data = fs.readFileSync(files.file[0].path)
try {
const added = await ipfs.add(data)
fs.unlinkSync(files.file[0].path);
return res.status(200).send({ "ipfs success": added})
} catch (err) {
fs.unlinkSync(files.file[0].path);
return res.status(500).send({ "ipfs error": error})
}
})
})
Version
“ipfs-http-client”: “^52.0.4-rc.4”