react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

Uploading file on Android

Open Patatruffe34 opened this issue 9 years ago • 16 comments

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

Patatruffe34 avatar Apr 12 '17 14:04 Patatruffe34

Hey can you show some code please?

Ehesp avatar Apr 12 '17 15:04 Ehesp

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

Patatruffe34 avatar Apr 12 '17 17:04 Patatruffe34

@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?

Ehesp avatar Apr 12 '17 21:04 Ehesp

You want me to try something ?

Patatruffe34 avatar Apr 13 '17 05:04 Patatruffe34

@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.

Ehesp avatar Apr 13 '17 07:04 Ehesp

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")

Patatruffe34 avatar Apr 13 '17 09:04 Patatruffe34

@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.

Salakar avatar Apr 16 '17 12:04 Salakar

I took your code from github but still got the same error (running on simulator)

Patatruffe34 avatar Apr 16 '17 13:04 Patatruffe34

I got the last version and I have this error now on iOS :

"_firebase2.default.storage(...).ref(...).putFile(...).then is not a function"

Thanks

Patatruffe34 avatar May 04 '17 13:05 Patatruffe34

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

Patatruffe34 avatar May 04 '17 14:05 Patatruffe34

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)

Patatruffe34 avatar May 04 '17 14:05 Patatruffe34

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

Patatruffe34 avatar May 05 '17 15:05 Patatruffe34

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 .

Piyush132000 avatar Dec 12 '20 08:12 Piyush132000

Can you please open a fresh issue?

mikehardy avatar Dec 12 '20 13:12 mikehardy

please if anyone know my problem please reply

Piyush132000 avatar Dec 12 '20 14:12 Piyush132000

@Piyush132000 you are commenting on a 3 year old, closed issue.

I repeat: Please open a fresh issue

mikehardy avatar Dec 12 '20 21:12 mikehardy