joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.84k stars 787 forks source link

[iOS] cannot access media stats from cameraroll with RN 0.59.1 #337

Open sulagarde opened 5 years ago

sulagarde commented 5 years ago

Since I upgraded react-native 0.59.1 I cannot get stats from iOs files: Error: failed to stat path ph://9F983DBA-EC35-42B8-8773-B597CF782EDD/L0/001 because it does not exist or it is not a folder.

dmitryame commented 5 years ago

I'm also having issues uploading to AWS s3 with the fetch after upgrading RN to 0.59.x. The issue here is that CameraRoll.saveToCameraRoll returns URI that is prefixed with ph:// instead of assets-library://, as the result the RNFetchBlob.fetch('PUT',.. does not return any error, but uploads 0 bytes.

RafikiTiki commented 5 years ago

I don't have any experience in native side of development for iOS but I've tracked down that react-native changed the way uri is formatted in 0.59.x and above versions.

Pre 0.59 code: https://github.com/facebook/react-native/blob/0.58-stable/Libraries/CameraRoll/RCTCameraRollManager.m#L202

0.59+ code: https://github.com/facebook/react-native/blob/master/Libraries/CameraRoll/RCTCameraRollManager.m#L131

dmitryame commented 5 years ago

Yep, this seems to be correct. So, is it going to be addressed by the rn-fetch-blob? Because as of now, I can not use it with rn 0.59.x.

samparmenter commented 5 years ago

rn-fetch-blob is no longer maintained and won't receive any updates by the looks of it.

You can get around it by doing something like this but I don't imagine its very robust

uri = ph://9F983DBA-EC35-42B8-8773-B597CF782EDD/L0/001
ext = 'jpg'; // or heic or png etc
uri = uri.replace('ph://', '');      
localIdentifier = uri.split('/')[0]; // leaves 9F983DBA-EC35-42B8-8773-B597CF782EDD
filePath = `assets-library://asset/asset.${ext}?id=${localIdentifier}&ext=${ext}`; // this you can pass into rn-fetch-blob stuff

This isn't my fix but it seems to at least work for now

dmitryame commented 5 years ago

Thank you for your reply, really appreciate it. And this is very unfortunate news, because I was only able to get AWS upload to work correctly with rn-fetch-blob . I wonder, what are the other alternatives people use these days for this kind of stuff. Thanks.

20pro commented 5 years ago

rn-fetch-blob is no longer maintained and won't receive any updates by the looks of it.

You can get around it by doing something like this but I don't imagine its very robust

uri = ph://9F983DBA-EC35-42B8-8773-B597CF782EDD/L0/001
ext = 'jpg'; // or heic or png etc
uri = uri.replace('ph://', '');      
localIdentifier = uri.split('/')[0]; // leaves 9F983DBA-EC35-42B8-8773-B597CF782EDD
filePath = `assets-library://asset/asset.${ext}?id=${localIdentifier}&ext=${ext}`; // this you can pass into rn-fetch-blob stuff

This isn't my fix but it seems to at least work for now

@samparmenter Why rn-fetch-blob won't receive any update ?

zoozalp commented 5 years ago

@samparmenter Why rn-fetch-blob won't receive any update ?

see #359

akontaroudis commented 5 years ago

rn-fetch-blob is no longer maintained and won't receive any updates by the looks of it.

You can get around it by doing something like this but I don't imagine its very robust

uri = ph://9F983DBA-EC35-42B8-8773-B597CF782EDD/L0/001
ext = 'jpg'; // or heic or png etc
uri = uri.replace('ph://', '');      
localIdentifier = uri.split('/')[0]; // leaves 9F983DBA-EC35-42B8-8773-B597CF782EDD
filePath = `assets-library://asset/asset.${ext}?id=${localIdentifier}&ext=${ext}`; // this you can pass into rn-fetch-blob stuff

This isn't my fix but it seems to at least work for now

Has this worked for anyone? Trying to copy a file with cp where the source file being an assets-library path results in an empty file to the destination path.

For what is worth using react-native-fs with copyAssetsFileIOS and formatting the path with the above code snippet seems to work. I guess there's most probably an issue with rn-fetch-blob itself.