This does not work with a self-hosted server, you can use uploadFolder instead
Saving Files
IPFS is supported out of the box when using Moralis.
You can upload files with the saveIPFS() method (max file size 1 GB).
// Save file input to IPFSconstdata=fileInput.files[0];constfile=newMoralis.File(data.name, data);awaitfile.saveIPFS();//console.log(file.ipfs(), file.hash())// Save file reference to MoralisconstjobApplication=newMoralis.Object("Applications");jobApplication.set("name","Satoshi");jobApplication.set("resume", file);awaitjobApplication.save();// Retrieve fileconstquery=newMoralis.Query("Applications");query.equalTo("name","Satoshi");query.find().then(function ([application]) {constipfs=application.get("resume").ipfs();consthash=application.get("resume").hash();console.log("IPFS url", ipfs);console.log("IPFS hash", hash);});
The data is automatically pinned.
Saving Objects
You can also upload JSON objects directly from JavaScript, by saving the base64 string, Moralis will automatically create the buffer from the base64 provided:
Displaying content on websites that was uploaded via Moralis
Moralis public IPFS gateway is not for:
Running scripts downloading content from IPFS. The Moralis public gateway has a JS Challenge blocking scripts for abuse protection. If your use-case requires you to run script downloading a lot of IPFS data we recommend Infura or Pinata.
Accessing files on IPFS that weren't uploaded via Moralis.