upload
Upload arbitrary file or JSON data using the configured decentralized storage system (IPFS with pinning by default).
Usage
Upload file or JSON data to the decentralized storage system.
If uploading a JSON object, the method will automatically upload any file data within the object and replace it with a hash.
const data = { name: "Hello world" };
const uri = await storage.upload(data);
Configuration
data
The data you want to upload.
Accepts any data type (File, object, string, etc).
By default, the data is uploaded and pinned to IPFS for you.
options (optional)
Customize the upload behaviour by passing in an options object as the second parameter.
const uri = await storage.upload(
{ name: "Hello world" },
{
alwaysUpload: false, // Optionally, always reupload even if the file already exists
onProgress: (progress) => {}, // Callback that gets triggered when file upload progresses
metadata: {}, // Optional metadata to associate with this upload
rewriteFileNames: undefined, // If specified, will rewrite file names to numbers for use on-chain. Useful to use with NFT contracts that map token IDs to files.
uploadWithGatewayUrl: false, // If specified, any URLs with schemes will be replaced with resolved URLs before upload
uploadWithoutDirectory: false, // If specified, will upload a single file without wrapping it in a directory
},
);
Return Value
Returns the URI of the uploaded data (ex: ipfs://<CID>
).
string;