TypeError: Cannot create a Parse.File with that data

Try not passing that object into multer.memoryStorage on the first line

Will it work for NFT? https://ipfs.moralis.io:2053/ipfs/QmNuxgpo3vGppRoZKMBsYU16gq23ydiPCTUcjbj4J23KuC

No, that won’t work, can you show me the line where you make the moralis file instance?

File instance codes:
const fileType = req.file.mimetype;
const value = fileType.substring(fileType.lastIndexOf(’/’) + 1);
const imageFile = new Moralis.File(myNFT.${value}, {base64 : btoa(JSON.stringify(file))});

await imageFile.saveIPFS({useMasterKey: true});
imageURI = imageFile.ipfs();

Multer codes:

let storage = multer.memoryStorage({
destination: (req, file, cb) => cb(null, ‘uploads/’),
})

let upload = multer({
storage: storage,
fileFilter: (req, file, cb) => {
if (file.mimetype == “image/png” || file.mimetype == “image/jpg” || file.mimetype == “image/jpeg”) {
cb(null, true);
} else {
cb(null, false);
return cb(new ApiError(4002, ‘Only .png, .jpg and .jpeg format allowed!’));
}
},
limits: {
fileSize: 1024 * 1024 * 1
},
}).single(‘image’);

Also have tried without the multer local storage. Not getting the solve yet. Maybe there is the problem with this line only: “const imageFile = new Moralis.File(myNft.${value}, {base64 : btoa(JSON.stringify(file))});”

This as is right now returned the ipfs link you sent above?

Yes. Here is the another link: https://ipfs.moralis.io:2053/ipfs/QmaSGHimt6rpWDUtDu1wZg6qRGcZmjt17kYVnHUjmYhhoD

Have you tried this - I wrote //CHANGE HERE where I made changes

File instance codes:
const fileType = req.file.mimetype;
const value = fileType.substring(fileType.lastIndexOf(’/’) + 1);
const imageFile = new Moralis.File(myNFT.${value}, {base64 : req.file.buffer.toString("base64")}); //CHANGE HERE

await imageFile.saveIPFS({useMasterKey: true});
imageURI = imageFile.ipfs();

Multer codes:

let storage = multer.memoryStorage() //CHANGE HERE

let upload = multer({
storage: storage,
fileFilter: (req, file, cb) => {
if (file.mimetype == “image/png” || file.mimetype == “image/jpg” || file.mimetype == “image/jpeg”) {
cb(null, true);
} else {
cb(null, false);
return cb(new ApiError(4002, ‘Only .png, .jpg and .jpeg format allowed!’));
}
},
limits: {
fileSize: 1024 * 1024 * 1
},
}).single(‘image’);
2 Likes

Yes. I just tried this and this is working perfectly.

Thank you so much man. Thanks a lot. really glad to you.

1 Like

uploadimage = async(fileobj) => {

// const files = new Moralis.File(fileobj);

// await files.saveIPFS({useMasterKey:true});

// console.log(files.ipfs());

// return files.ipfs();



const fileType = fileobj.mimetype;

const value = fileType.substring(fileType.lastIndexOf(`/`) + 1);

const imageFile = new Moralis.File(myNFT.${value}, {base64 : req.file.buffer.toString("base64")});

await imageFile.saveIPFS({useMasterKey: true});

imageURI = imageFile.ipfs();

console.log(imageURI);

}

ERROR

const imageFile = new Moralis.File(myNFT.${value}, {base64 : req.file.buffer.toString(“base64”)});
^

SyntaxError: missing ) after argument list

what to do here please help me out.

my image name is 1.jfif, so is their any need to change anything in myNFT.${value}

what is your myNFT here ? Is it image name ?

You could have it as `myNFT.${value}` rather

uploadimage = async(fileobj) => {

const fileType = fileobj.mimetype;

//console.log(fileType);

const value = fileType.substring(fileType.lastIndexOf(`/`) + 1);

//console.log(value);

const imageFile = new Moralis.File(`myNFT.${value}`, {base64 : fileobj.buffer.toString("base64")});

// console.log(imageFile);

await imageFile.saveIPFS({useMasterKey: true});

imageURI = imageFile.ipfs();

console.log(imageURI);

}

Is it correct ?

ParseError: File upload by public is disabled.

I am gettiing this error

i didn’t got it, can you please explain

What’s explained is you can try to make authenticate with a username and password to grant auth access to upload the file

I have already imported Moralis and given appid, secret key , master key.

then why to again login

You can try initialize moralis with masterKey in such way Moralis.start({ serverUrl, appId, masterKey }); and using masterKey in your save .saveIPFS({ useMasterKey: true });

I did it then also not working