wkh237 / rn-firebase-storage-upload-sample

React Native sample code for upload blob data to Firebase using Firebase SDK with RNFetchBlob.
57 stars 13 forks source link

Hardcoded file name from my CameraRoll fails #5

Open MrRoyce opened 8 years ago

MrRoyce commented 8 years ago

Interesting I can get the sample program to work correctly if I use it as is, but if I hardcode the file name to a file from my CameraRoll such as let rnfbURI = RNFetchBlob.wrap('file:/storage/emulated/0/DCIM/Camera/IMG_20160626_154134.jpg')

it fails with the message I reported in the other thread:

The callback slice() exists in module RNFFetchBlob, but only one callback may be registered to a function in a native module.

wkh237 commented 8 years ago

@MrRoyce , try to remove file: prefix and see if it works correctly, thank you 😄

MrRoyce commented 8 years ago

That works! Thank you!

But of course there is something else! ;) For some odd reason, I can't upload the same image 2x. If I try to upload the same image from my CameraRoll multiple times, I get an error message from Firebase, that the image cant be found?? Even though I can still see the image, with the same name on the camera!

I finally decided to try a different image, and it works. But if I try to re-upload that same image again, I get that same error message?? I guess this issue can be closed, but not sure if you want to look into this??

wkh237 commented 8 years ago

Did you close the blob after upload ? If you create a Blob instance from exsiting file path, the file will be removed when blob.close() invoked, see document. I think this is a caveat perhaps we can change this design.

MrRoyce commented 8 years ago

Yes, I closed the blob as shown in the sample code.

I had no idea that the file would be deleted! That is very unexpected behavior and probably unwanted. I think that should not be the default, but maybe an option such as blob.delete(). I looked at the docs just now and I didn't see where it says the file will be deleted with a close(). Maybe that needs to be highlighted in several places as a warning.

But as I said, the image isn't totally deleted from the device. The name still exists, and a thumbnail can be viewed, but the actual file is unavailable. This leaves very odd behavior on my Nexux 6, in that if I view a grid of the images, the deleted ones are shone as blank???

wkh237 commented 8 years ago

@MrRoyce , thanks for your advices. I think you're right, I'll add these information to the document. As for the strange behavior about after the deleted files, I'd like to know more information and see anything I can do 😄

You've mentioned the deleted files are still visible, what's the files' URI look like ? where do they exists ? Downloads app or Gallery ?

If a file can be accessed via system apps (Downloads, Gallery, Music ..) that usually means they've scanned by Android media scanner. Media scanner will create an entry in meida content database and keep a reference to the files.

However, if we programatically remove the file, we should also use fs.scanFile again to update the status of the entry.

gilra2000 commented 8 years ago

please android camera image upload sample code ~~~