@@ -8,7 +8,7 @@ import {compressJson} from "./compressJson";
88import { STUDY_UNCOMPRESSED_KEYS } from "../model/study" ;
99import { collection , setDoc } from "@firebase/firestore" ;
1010import { doc } from "firebase/firestore" ;
11- import { uploadBytes } from "@firebase/storage" ;
11+ import { uploadBytesResumable } from "@firebase/storage" ;
1212import { ref } from "firebase/storage" ;
1313
1414/**
@@ -22,10 +22,11 @@ export function uploadStudyConfiguration(study) {
2222
2323/**
2424 * Uploads the image {@param image} to storage at the path {@param path}.
25- * @return {firebase.storage. UploadTask } a task object for tracking the upload.
25+ * @return {UploadTask } a task object for tracking the upload.
2626 */
2727export function uploadImageToStorage ( path , image ) {
28- return uploadBytes ( ref ( storage , path ) , image . buffer ) ;
28+ const metadata = { contentType : "image/" + image . type } ;
29+ return uploadBytesResumable ( ref ( storage , path ) , image . buffer , metadata ) ;
2930}
3031
3132/**
@@ -62,16 +63,16 @@ export function uploadImagesToStorage(imageDict, progressFn) {
6263 }
6364 } ) . catch ( ( error ) => {
6465 console . log ( "Error uploading " + path ) ;
65- try {
66- console . error ( error ) ;
67- progress . errored = true ;
68- // If any upload errors, cancel all other uploads.
69- for ( let index = 0 ; index < tasks . length ; ++ index ) {
70- tasks [ index ] . cancel ( ) ;
71- }
72- } finally {
73- reject ( error ) ;
66+ console . error ( error ) ;
67+ if ( progress . errored )
68+ return ;
69+
70+ progress . errored = true ;
71+ // If any upload errors, cancel all other uploads.
72+ for ( let index = 0 ; index < tasks . length ; ++ index ) {
73+ tasks [ index ] . cancel ( ) ;
7474 }
75+ reject ( error ) ;
7576 } ) ;
7677 tasks . push ( task ) ;
7778 progress . started += 1 ;
0 commit comments