Uploading file on Android
Hi guys,
The file upload works fine on iOS but on android, storage() send me the error "An unknown error has occurred" with no more informations
Any ideas ?
Best
Romain
Hey can you show some code please?
ahah yes, sorry, I thought you were a magician ;)
Here you are :
firebase.storage().
ref(remotePath)
.putFile(localPath)
.then(uploadedFile => {
firebase.database()
.ref(linkPath)
.set({
url: uploadedFile.downloadUrl
})
.then(() => {
this.setState({
loading:false,
progression:1
});
})
})
.catch(err => {
console.log("KAYO : " +err);
});
Cheers
@Salakar @chrisbianca this seems to throw the error that promise is not defined.
export default class StorageTask {
constructor(type: string, promise, storageRef) {
this.type = type;
this.ref = storageRef;
this.promise = promise;
this.storage = storageRef.storage;
this.path = storageRef.path;
// 'proxy' original promise
this.then = promise.then.bind(promise);
this.catch = promise.catch.bind(promise);
}
Error on: this.then = promise.then.bind(promise);. Also just doing an on seems to throw an error as well?
You want me to try something ?
@Panda313 Try downgrading to alpha10, and trying the following:
firestack.storage().ref(ref).putFile(uri)
.on('state_changed', (snapshot) => {
}, (err) => {
}, (uploadedAsset) => {
})
I mentioned to @Salakar that then then/catch wasn't working, and after checking out the web SDK further there's loads of ways to do the same thing (callbacks, promises, listeners etc). Salakar started some work on it, but I'm not sure what the current state of it is/whats broke.
I tried, here is the result :
Possible Unhandled Promise
Rejection (id: 0):
An unknown error has occurred.
Error: An unknown error has occurred.
at createErrorFromErrorData
and my code :
firebase.storage().ref(remotePath).putFile(photoPath)
.on('state_changed', (snapshot) => {
console.log("SNAPSHOT = ");
console.log(snapshot);
}, (err) => {
console.log("KAYO :( " +err);
}, (uploadedAsset) => {
console.log("UPLOAD ASSETS ");
});
I logged SNAPSHOT 2 times (one with state "running" and one with state "success")
@Panda313 @Ehesp I fixed this issue 9 days ago, just needs a new release - haven't been able to test it fully hence no release, could you try install the npm module direct from github and let me know if it fixes yours issue - if so I'll do a release.
I took your code from github but still got the same error (running on simulator)
I got the last version and I have this error now on iOS :
"_firebase2.default.storage(...).ref(...).putFile(...).then is not a function"
Thanks
Fixed it on iOS using :
const unsubscribe = firebase.storage()
.ref('/files/1234')
.putFile('/path/to/file/1234')
.on('state_changed', snapshot => {
//Current upload state
}, err => {
//Error
unsubscribe();
}, uploadedFile => {
//Success
unsubscribe();
});
Still not working on android
The error is now :
Possible Unhandled Promise Rejection (id: 0): An unknown error has occurred. Error: An unknown error has occurred. at createErrorFromErrorData (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5312:15) at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5270:25 at MessageQueue.__invokeCallback (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5592:16) at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5453:16 at guard (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5392:5) at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:5452:7) at addEventListener (file:///Applications/React%20Native%20Debugger.app/Contents/Resources/app.asar/js/RNDebuggerWorker.js:1:21894)
FOUND IT !
My local file path start with "file:/", wich is not a probleme on iOS but on Android, you're still adding "file:/". Wich make it crash.
I juste remove "file:/" from the local path and it works.
Cheers
Possible Unhandled Promise Rejection (id: 17): Error: [storage/file-not-found] The local file specified does not exist on the device. NativeFirebaseError: [storage/file-not-found] The local file specified does not exist on the device.
i am getting this every time on uploading image .
Can you please open a fresh issue?
please if anyone know my problem please reply
@Piyush132000 you are commenting on a 3 year old, closed issue.
I repeat: Please open a fresh issue