firebase-js-sdk
firebase-js-sdk copied to clipboard
Firebase Storage UploadTask Snapshot does not progress and completion callback/promise is never returned.
[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);
});
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.
Same issue, tested using angularfire. OS: Windows 10 Browser: Chrome Firebase SDK version: 7.14.3
Any work around for this?
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();
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.
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
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
Found this error as well, any update?
Also experiencing this error with firebase emulator - OSX monterrey 12.3 firebase sdk 10.4.2 firebase products: auth, firestore, functions, storage
Hi, Firebase JS SDK's latest version is 9.8.2, did you mix up version numbers with another library?
Same issue as well. Multiple file uploads causes only one to complete and the rest to not trigger the completion callback.
Getting the same issue on flutter sdk. It worked perfectly on 27/06/2022. But now files uploads are getting stuck on 0%.
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
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 - 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?
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.
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