[ARVADOS-WORKBENCH2] updated: 1.1.4-593-gd260d24

Git user git at public.curoverse.com
Mon Aug 13 11:05:14 EDT 2018


Summary of changes:
 src/common/file.ts                                 | 12 ++++++++
 .../collection-service/collection-service.ts       | 33 +++++++++-------------
 2 files changed, 25 insertions(+), 20 deletions(-)
 create mode 100644 src/common/file.ts

       via  d260d2473cd7faefb0f06cedfb26ef5abda7e012 (commit)
      from  8c259b5122df8254613e8d23b0d860a7b1b37b41 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit d260d2473cd7faefb0f06cedfb26ef5abda7e012
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date:   Mon Aug 13 17:04:55 2018 +0200

    Extract file utils
    
    Feature #14013
    
    Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>

diff --git a/src/common/file.ts b/src/common/file.ts
new file mode 100644
index 0000000..3f17a38
--- /dev/null
+++ b/src/common/file.ts
@@ -0,0 +1,12 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+export const fileToArrayBuffer = (file: File) =>
+    new Promise<ArrayBuffer>(resolve => {
+        const reader = new FileReader();
+        reader.onload = () => {
+            resolve(reader.result as ArrayBuffer);
+        };
+        reader.readAsArrayBuffer(file);
+    });
diff --git a/src/services/collection-service/collection-service.ts b/src/services/collection-service/collection-service.ts
index 3b98f75..c611f36 100644
--- a/src/services/collection-service/collection-service.ts
+++ b/src/services/collection-service/collection-service.ts
@@ -10,6 +10,7 @@ import { WebDAV } from "../../common/webdav";
 import { AuthService } from "../auth-service/auth-service";
 import { mapTreeValues } from "../../models/tree";
 import { parseFilesResponse } from "./collection-service-files-response";
+import { fileToArrayBuffer } from "../../common/file";
 
 export type UploadProgress = (fileId: number, loaded: number, total: number, currentTime: number) => void;
 
@@ -42,27 +43,19 @@ export class CollectionService extends CommonResourceService<CollectionResource>
         url: this.webdavClient.defaults.baseURL + file.url + '?api_token=' + this.authService.getApiToken()
     })
 
-    private uploadFile(collectionUuid: string, file: File, fileId: number, onProgress: UploadProgress = () => { return; }) {
-        return this.readFile(file).then(content =>
-            this.webdavClient.put(`/c=${collectionUuid}/${file.name}`, content, {
-                headers: {
-                    'Content-Type': 'text/octet-stream'
-                },
-                onUploadProgress: (e: ProgressEvent) => {
-                    onProgress(fileId, e.loaded, e.total, Date.now());
-                }
-            })
-        );
-    }
+    private async uploadFile(collectionUuid: string, file: File, fileId: number, onProgress: UploadProgress = () => { return; }) {
+        const fileURL = `/c=${collectionUuid}/${file.name}`;
+        const fileContent = await fileToArrayBuffer(file);
+        const requestConfig = {
+            headers: {
+                'Content-Type': 'text/octet-stream'
+            },
+            onUploadProgress: (e: ProgressEvent) => {
+                onProgress(fileId, e.loaded, e.total, Date.now());
+            }
+        };
+        return this.webdavClient.put(fileURL, fileContent, requestConfig);
 
-    private readFile(file: File): Promise<ArrayBuffer> {
-        return new Promise<ArrayBuffer>(resolve => {
-            const reader = new FileReader();
-            reader.onload = () => {
-                resolve(reader.result as ArrayBuffer);
-            };
-            reader.readAsArrayBuffer(file);
-        });
     }
 
 }

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list