Skip to main content

RemoteStorage.upload() method

Upload any data to an IPFS directory. We'll handle all the details for you, including pinning your files and making sure that you get the fastest upload speeds.

Example

// File upload
const files = [fs.readFileSync("file1.png"), fs.readFileSync("file2.png")];
const result = await sdk.storage.upload(files);
// uri for each uploaded file will look like something like: ipfs://<hash>/0

// JSON metadata upload
const jsonMetadata = {
name: "Name",
description: "Description",
};
const result = await sdk.storage.upload(jsonMetadata);

// Upload progress (browser only)
const result = await sdk.storage.upload(files, {
onProgress: (event: UploadProgressEvent) => {
console.log(`Downloaded ${event.progress} / ${event.total}`);
},
});

Signature:

upload(data: FileOrBuffer[] | JsonObject[] | FileOrBuffer | JsonObject, options?: {
onProgress: (event: UploadProgressEvent) => void;
}): Promise<UploadResult>;

Parameters

ParameterTypeDescription
dataFileOrBuffer[] | JsonObject[] | FileOrBuffer | JsonObjectAn array of file data or an array of JSON metadata to upload to IPFS
options{ onProgress: (event: UploadProgressEvent) => void; }(Optional) Optional. Upload progress callback.

Returns:

Promise<UploadResult>

The IPFS hash of the directory that holds all the uploaded data