Use the upload
method to upload and replicate a file to Sia Network automatically.
try {
const file = /* your file data */; // Your file input or Blob.
const directoryId = 'directory_id_here'; // The ID of the target directory.
const filePath = "driveid_folder1id_folder2id"; // Location of your file
const replicateTo = { SIA: true };
const [data, error] = await sdk.file.upload({
file,
directoryId,
filePath,
replicateTo
});
// Check for success
if (error) {
console.error("Failed to upload the file:", error);
} else {
console.log("File uploaded successfully:", data);
}
} catch (error) {
console.error("An unexpected error occurred:", error.message);
}
Params
file
(formData): The file data to be uploaded.directoryId
(string): The ID of the target directory.filePath
(string): Location of your file (ex. driveid/folder1id/folder2id)replicateTo
(object): An object containing the desired DSN to replicate to.
Required API Key Permission
Upload File