diff --git a/src/methods/upload-file.ts b/src/methods/upload-file.ts index 704923f..2c20594 100644 --- a/src/methods/upload-file.ts +++ b/src/methods/upload-file.ts @@ -10,11 +10,13 @@ import nacl from "tweetnacl"; * * @param {web3.PublicKey} key - Publickey of Storage Account. * @param {File | ShadowFile} data - File or ShadowFile object, file extensions should be included in the name property of ShadowFiles. + * @param {Boolean} overwrite - If true, overwrites if existing. Default is false. * @returns {ShadowUploadResponse} File location and transaction signature. */ export default async function uploadFile( key: web3.PublicKey, - data: File | ShadowFile + data: File | ShadowFile, + overwrite: Boolean = false ): Promise { let fileErrors = []; let fileBuffer: Buffer; @@ -82,6 +84,9 @@ export default async function uploadFile( form.append("message", encodedMsg); form.append("storage_account", key.toString()); form.append("signer", this.wallet.publicKey.toString()); + if(overwrite) { + form.append("overwrite", "true"); + } } catch (e) { return Promise.reject(new Error(e.message)); } diff --git a/src/methods/upload-multiple-files.ts b/src/methods/upload-multiple-files.ts index c955edc..9903fdd 100644 --- a/src/methods/upload-multiple-files.ts +++ b/src/methods/upload-multiple-files.ts @@ -22,6 +22,7 @@ interface FileData { * @param {web3.PublicKey} key - Storage account PublicKey to upload the files to. * @param {FileList | ShadowFile[]} data[] - Array of Files or ShadowFile objects to be uploaded * @param {Number} concurrent - Number of files to concurrently upload. Default: 3 + * @param {Boolean} overwrite - If true, overwrites if existing. Default is false. * @param {Function} callback - Callback function for every batch of files uploaded. A number will be passed into the callback like `callback(num)` indicating the number of files that were confirmed in that specific batch. * @returns {ShadowBatchUploadResponse[]} - File names, locations and transaction signatures for uploaded files. */ @@ -30,7 +31,8 @@ export default async function uploadMultipleFiles( key: web3.PublicKey, data: FileList | ShadowFile[], concurrent = 3, - callback?: Function + overwrite: Boolean = false, + callback?: Function, ): Promise { let fileData: Array = []; const fileErrors: Array = []; @@ -218,6 +220,9 @@ export default async function uploadMultipleFiles( fd.append("storage_account", key.toString()); fd.append("signer", this.wallet.publicKey.toString()); fd.append("fileNames", allFileNames.toString()); + if (overwrite) { + fd.append("overwrite", "true"); + } const controller = new AbortController(); const timeoutId = setTimeout(() => controller.abort(), 7200000); const response = await fetch(`${SHDW_DRIVE_ENDPOINT}/upload`, {