Uploading a static file to IPFS with Moralis


I’m trying to mint an NFT using a static file that is imported locally, so first I want to upload the media file to IPFS using Moralis. This is an example of what I’ve attempted:

import exampleImage from "../example/image.png"

const file1 = new Moralis.File(file.name, {base64:{exampleImage}});
      await file1.saveIPFS();
      const file1url = file1.ipfs();

Then I use the returned url to create a metadata file. Using the metadata file I can successfully create an NFT, but when I check the NFT on opensea the image seems to be null… I’ve waited and refreshed the metadata a few times within OS and that did not seem to help.

When I input the url I get back from storing the image to IPFS into my browser, it automatically downloads a file not containing my image but instead a string of characters

Lastly, when I attempt to omit the base64 parameter:

const file1 = new Moralis.File(file.name, {exampleImage});
await file1.saveIPFS();
const file1url = file1.ipfs();

I get: “TypeError: Cannot create a Parse.File with that data”

Anyone know what I can do to be able to use my static file with IPFS?


What does the returned URL or file look like?

Hey thank s for the response,

This is the file I get back from setting the media file with IPFS: https://ipfs.moralis.io:2053/ipfs/QmSfw8FFAcimb3vgSKMpxmjD1Y2zrjvt8WB43PY469nTyS

When did you try this? The returned url is not the expected one for the domain that it should return.

Also, maybe you can read the binary contents of the file without using import and then to convert those contents to base64.

Yeah, I wasn’t able to decipher what I was looking at with this url… but this was tried maybe around 20 hours ago

I am willing to try this option, but could you maybe explain a little further into detail how I would go about reading the binary contents without using import?

Thank you for the help!

You can search on google how to read the contents of a binary file in nodejs. I don’t know the exact code now. It should be something easy.

1 Like

Appreciate it, Ill test it out and post how it went

Did you figure this out? Trying to debug this issue right now.