Usually this error means that you are not authenticated
Hmm, how do I authenticate? In the moralis.initialize(“appid” , “”, “master key”)? This still gives the same error
you could try to use await metadataFile.saveIPFS({useMasterKey:true});
This worked, thanks!
how are you hiding the master Key ?
you don’t have to hide it when you run cloud functions, in front end you should not use the master key
I also get the same error:
Here’s my code:
const image = "data:image/png;base64," + btoa(svgData);
Moralis.initialize(
MORALIS_APP_ID,
"",
MORALIS_MASTER_KEY
);
const file = new Moralis.File(
"smolrunners_" + String(supply) + ".svg",
{base64 : image }
);
await file.saveIPFS({useMasterKey:true});
Can anyone tell me how to fix this issue?
i used it then also it is showing me same error
did you try with await file.saveIPFS(null, {useMasterKey:true});
?
yes i did.
can i show my code so you can help me
you can use uploadFolder from web3api directly too in order to upload to IPFS
const Moralis = require(“moralis/node”);
const express = require(‘express’);
const multer = require(‘multer’);
let storage = multer.memoryStorage()
const upload = multer({storage: storage , dest: ‘uploads/’});
const router = express.Router();
const serverUrl = “…”;
const appId = “…”;
const masterkey = “…”
Moralis.start({ serverUrl, appId, masterkey});
router.post(’/get_and_convert’,upload.single(‘file’), async (req,res) => {
const imagestring = await uploadimage(req.file);
console.log(imagestring);
const imagefiles = new transaction({
image : imagestring,
})
try {
const dataToSave = await imagefiles.save();
res.status(200).json(dataToSave)
}
catch (error) {
res.status(400).json({ message: error.message })
}
})
uploadimage = async(fileobj) => {
const fileType = fileobj.mimetype;
const value = fileType.substring(fileType.lastIndexOf(`/`) + 1);
const imageFile = new Moralis.File(`myNFT.${value}`, {base64 : fileobj.buffer.toString("base64")});
await imageFile.saveIPFS(null,{useMasterKey: true});
imageURI = imageFile.ipfs();
console.log(imageURI);
}
what is issue because of which i am getting that error
Please let me know a early as possible
please check here on how to post code on forum:
can you please check once the code.
this works fine for me:
const Moralis = require('moralis/node')
const serverUrl = 'https://23423:2053/server'
const appId = '5234'
const masterKey = '523425'
async function x() {
await Moralis.start({serverUrl: serverUrl, appId: appId, masterKey: masterKey})
const imageFile = new Moralis.File("test_file", {base64 : "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAApgAAAKYB3X3"});
f = await imageFile.saveIPFS({useMasterKey: true});
console.log(JSON.stringify(f))
}
x()
But I want IPFS link so what changes are required in this
if you run that code, you can see the output and you can find out after that how to get the url for ipfs
Same error with this also