aboutsummaryrefslogtreecommitdiff
path: root/src/client/Network.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Network.ts')
-rw-r--r--src/client/Network.ts16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/client/Network.ts b/src/client/Network.ts
index 28825823d..9c293f9af 100644
--- a/src/client/Network.ts
+++ b/src/client/Network.ts
@@ -17,19 +17,26 @@ export namespace Networking {
return requestPromise.post(options);
}
+ /**
+ * FileGuidPair attaches a guid to a file that is being uploaded,
+ * allowing the client to track the upload progress.
+ *
+ * When files are dragged to the canvas, the overWriteDoc's ID is
+ * used as the guid. Otherwise, a new guid is generated.
+ */
export interface FileGuidPair {
file: File;
guid?: string;
}
/**
* Handles uploading basic file types to server and makes the API call to "/uploadFormData" endpoint
- * with the mapping of GUID to filem as parameters.
+ * with the mapping of guid to filem as parameters.
*
- * @param fileguidpairs the files to be uploaded to the server
+ * @param fileguidpairs the files and corresponding guids to be uploaded to the server
* @returns the response as a json from the server
*/
export async function UploadFilesToServer<T extends Upload.FileInformation = Upload.FileInformation>(fileguidpairs: FileGuidPair | FileGuidPair[]): Promise<Upload.FileResponse<T>[]> {
- const formData = new FormData();
+ const formData = new FormData();
if (Array.isArray(fileguidpairs)) {
if (!fileguidpairs.length) {
return [];
@@ -45,8 +52,11 @@ export namespace Networking {
])
);
}
+ // If the fileguidpair has a guid to use (From the overwriteDoc) use that guid. Otherwise,
+ // generate a new guid.
fileguidpairs.forEach(fileguidpair => formData.append(fileguidpair.guid ?? Utils.GenerateGuid(), fileguidpair.file));
} else {
+ // Handle the case where fileguidpairs is a single file.
formData.append(fileguidpairs.guid ?? Utils.GenerateGuid(), fileguidpairs.file);
}
const parameters = {