18834: Fixed uploading file to a subdirectory, added tests
[arvados-workbench2.git] / src / services / collection-service / collection-service.ts
index a3a7cf8f3af89c88ddd7edac938719199df74cbf..9165e245db41102ca1c49fd0ea3c16e317d98f9d 100644 (file)
@@ -88,11 +88,11 @@ export class CollectionService extends TrashableResourceService<CollectionResour
         await this.update(collectionUuid, { preserveVersion: true });
     }
 
-    async uploadFiles(collectionUuid: string, files: File[], onProgress?: UploadProgress) {
+    async uploadFiles(collectionUuid: string, files: File[], onProgress?: UploadProgress, targetLocation: string = '') {
         if (collectionUuid === "" || files.length === 0) { return; }
         // files have to be uploaded sequentially
         for (let idx = 0; idx < files.length; idx++) {
-            await this.uploadFile(collectionUuid, files[idx], idx, onProgress);
+            await this.uploadFile(collectionUuid, files[idx], idx, onProgress, targetLocation);
         }
         await this.update(collectionUuid, { preserveVersion: true });
     }
@@ -120,8 +120,8 @@ export class CollectionService extends TrashableResourceService<CollectionResour
         };
     }
 
-    private async uploadFile(collectionUuid: string, file: File, fileId: number, onProgress: UploadProgress = () => { return; }) {
-        const fileURL = `c=${collectionUuid}/${file.name}`;
+    private async uploadFile(collectionUuid: string, file: File, fileId: number, onProgress: UploadProgress = () => { return; }, targetLocation: string = '') {
+        const fileURL = `c=${targetLocation !== '' ? targetLocation : collectionUuid}/${file.name}`;
         const requestConfig = {
             headers: {
                 'Content-Type': 'text/octet-stream'