[SOLVED] File upload by public is disabled with node js

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

1 Like

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()
1 Like

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

it worked for me, did you properly set the master key?

f = await imageFile.saveIPFS(null,{useMasterKey: true});

error is shown at this line

from where you are taking test_file and bae64 value

test_file is the name that I gave it, it is hardcoded, base64 is the base64 contents of a buffer that I used

you have to know those values in advance depending on your use case, that is an example for hardcoded values

you can also use some debugging to see what are the values in your case, to see if they are the expected values

1 Like