firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

Firebase Storage UploadTask Snapshot does not progress and completion callback/promise is never returned.

Open giladrom opened this issue 4 years ago • 12 comments

[REQUIRED] Describe your environment

  • Operating System version: iOS13.4
  • Browser version: Mobile Safari
  • Firebase SDK version: 7.9.1
  • Firebase Product: Storage

[REQUIRED] Describe the problem

Firebase Storage UploadTask Snapshot does not progress and completion callback/promise is never returned.

I can see the file is created and uploaded properly using Firebase Console.

Steps to reproduce:

Upload a file using the firebase storage sdk, wait for task snapshot to return. Expected result: File is uploaded and progress is reported, and a download URL is returned (this worked until fairly recently, and I cannot determine exactly why this isn't working anymore)

Actual output:

console.log: Writing image to DB as image.jpeg...
console.log: Waiting for upload to finish...
console.log: running Upload Progress 0

<Nothing happens here and there's no timeout>

Relevant Code:

      const filename = "image.jpeg";
      console.log(`Writing image to DB as ${filename}...`);

      const uploadTask = firebase
        .storage()
        .ref()
        .child(filename)
        .put(blob, { contentType: "image/jpeg" });

      uploadTask.on(
        "state_changed",
        function(snap) {
          var progress = snap.bytesTransferred / snap.totalBytes / 100;
          console.log(snap.state, "Upload Progress", progress);
        },
        function(err) {
          console.error("Upload Error", err);
        }
      );

      console.log("Waiting for upload to finish...");

      await uploadTask.snapshot.ref
        .getDownloadURL()
        .then(url => {
          console.log("Upload Completed");

          resolve(url);
        })
        .catch(e => {
          reject(e);
        });

giladrom avatar Mar 23 '20 01:03 giladrom

I can report that I have the exact same problem, here are my specs if it helps:

  • Operating System version: Mac OS Catalina 10.15.3
  • Browser version: Firefox
  • Firebase SDK version: 7.9.1
  • Firebase Product: Storage

Edit: this is still hapening with the latest SDK (7.13.2) The POST call to https://firebasestorage.googleapis.com/v0/b/... just hangs forever.

Mytrill avatar Apr 07 '20 11:04 Mytrill

Same issue, tested using angularfire. OS: Windows 10 Browser: Chrome Firebase SDK version: 7.14.3

Any work around for this?

luc-anise avatar May 28 '20 02:05 luc-anise

I tried your code and even before 100% upload it is executing " upload complete" console log. Why don't you use 3rd optional complete function which you can pass along with next and error function and resolve and reject promise there?

const uploadTask = storage.ref(`images/${file.name}`).put(file);
    uploadTask.on("state_changed",
        snapshot => {
            const progress = Math.round((snapshot.bytesTransferred / snapshot.totalBytes) * 100);
            console.log(progress);
            put({ type: videoUploadActionType.updateProgress, progress });
        },
        error => {
            console.log(error);
            reject(error);
        },
        () => {
            storage.ref('images')
                .child(file.name)
                .getDownloadURL()
                .then(url => {
                    console.log('[completed. Dowload URL]' + url);
                    resolve(url);
                }); 
 });

Storage object has been imported from separate file here but behind the scenes it is generated via

firebase.initializeApp(<firebase_config>);
const storage = firebase.storage();

amitaggrawal avatar Sep 24 '20 16:09 amitaggrawal

Any progress on this issue? We facing the same issue with version 8.4.3. The problem only exists for slow internet speed (e.g. 3g). The upload will stuck at 0.

ssalom avatar Oct 26 '21 18:10 ssalom

Also experiencing this issue using the Firebase emulators Uploading files will get stuck on 0 bytesTransferred. Removing and rebinding the .on() listener minutes later will return the same image

The issue occurs intermittently however I have found that I can recreate it with some consistency by starting multiple tasks in quick succession (like uploading 6 files selected in an input). Files do upload but uploadTask never changes. I have found that once it has happened it will then happen consistently with every file I attempt following that.

Operating System version: WIndows 10 Version 10.0.19042 Build 19042 Browser version: Chrome Version 96.0.4664.45 (Official Build) (64-bit) Firebase SDK version: 8.6.7 Firebase Product: Storage

pklitscher avatar Dec 05 '21 08:12 pklitscher

Found this error as well, any update?

phath9 avatar Jun 02 '22 10:06 phath9

Also experiencing this error with firebase emulator - OSX monterrey 12.3 firebase sdk 10.4.2 firebase products: auth, firestore, functions, storage

frimmy avatar Jun 06 '22 05:06 frimmy

Hi, Firebase JS SDK's latest version is 9.8.2, did you mix up version numbers with another library?

hsubox76 avatar Jun 06 '22 18:06 hsubox76

Same issue as well. Multiple file uploads causes only one to complete and the rest to not trigger the completion callback.

hirvesh avatar Jun 15 '22 09:06 hirvesh

Getting the same issue on flutter sdk. It worked perfectly on 27/06/2022. But now files uploads are getting stuck on 0%.

jrcmadushanka avatar Jun 27 '22 18:06 jrcmadushanka

Having exactly the same problem (version 9.9.0) and made a stack overflow issue about it: https://stackoverflow.com/questions/73082962/firebase-upload-stuck-at-0-0-no-error-given

alligatorjazz avatar Jul 22 '22 16:07 alligatorjazz

I am encountering the same issue. It looks like the the upload only hangs for small files below around 250kb. Larger files are uploading as expected.

SteffenKeller avatar Aug 05 '22 13:08 SteffenKeller

@SteffenKeller - would you mind providing more details on this? What version of the JS SDK? Browser or Node? What version? Can you provide a reproducible example?

maneesht avatar Nov 01 '22 21:11 maneesht

After updating to version 9.13.0 it looks like all files are now uploading as expected. I was facing this issue with version 9.9.2 on Node.

SteffenKeller avatar Nov 02 '22 00:11 SteffenKeller

Just hit this problem with the emulator. Using p-queue to limit it to 2 concurrent uploads seems to always work, anything more and some never complete but also never fail, just hang.

Using: firebase tools: 11.23.1 firebase sdk: 9.17.1

CaptainCodeman avatar Feb 23 '23 21:02 CaptainCodeman