itinance / react-native-fs

Native filesystem access for react-native
MIT License
4.94k stars 976 forks source link

Support for photos:// URIs #373

Open sampurcell93 opened 6 years ago

sampurcell93 commented 6 years ago

Hi, with newer versions of iOS having buggy / deprecated support for the ALAsset lib, I've needed to shift to using iOS's new PHPhoto library. Unfortunately this seems to have poor support, in general among third party libraries, but it seems like it might be a good candidate for support in this library, especially since so many things depend on you.

Is there any plan to add support for this? If help is needed I can certainly take a stab at it.

Thanks! Sam

itinance commented 6 years ago

Although the main purpose of this library is to provide plain native access to the filesystem, we already provide some additional features like access to PHPhotoLibrary as used e.g. in copyAssetsFileIOS and copyAssetsVideoIOS.

Are there any concrete features you are missing or do you mean that methods like "copyFile" and readFile should be able to handle photos-URLs as well?

sampurcell93 commented 6 years ago

I was referring to some of the "core" functions like copyFile etc. working. But I think you're right - unless there's a way to read / copy / stat these photo:// uris without saving a temporary file somewhere, it might be best left to the user to use the copyAssets functions.

itinance commented 6 years ago

There is a reason behind these custom-schemes like "photo://" and so on. If we would provide them with "stat" or "read" we first would need to copy over them into a somewhat storage. And where should we put them? Temporary-Path? Cache-Path? Document-Path? Library-Path? When should we purge them? There is a lot of thinking behind those advanced techniques.

sampurcell93 commented 6 years ago

Yeah, exactly. The user should do what they need to do to get a local copy of the asset, then send it off the this lib as normal.

jagusiak commented 6 years ago

download via copyAssetsFileIOS, but previously change uri accordingly (for uri starting with photos://): uri = 'assets-library://asset/asset.JPG?id=' + uri.substr(9)

edwardmsmith commented 5 years ago

copyAssetsFileIOS does not seem to work with a photos:// uri.

the code:

RNFS.copyAssetsFileIOS(asset.image.uri, 'foo', 0, 0)
      .then(results => {
        console.log('Copy File', results);
      })
      .catch(err => {
        console.log('Error copying file', err);
      });

Results in the error:

Error copying file Error: Failed to fetch PHAsset with local identifier photos://691C9785-F56E-4194-B900-8FFD479FB7AD/L0/001 with no error message.
    at createErrorFromErrorData (NativeModules.js:146)
    at NativeModules.js:95
    at MessageQueue.__invokeCallback (MessageQueue.js:392)
    at MessageQueue.js:128
    at MessageQueue.__guard (MessageQueue.js:291)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:127)
    at t (RNDebuggerWorker.js:1)

As you can see from the error message, the uri was:

photos://691C9785-F56E-4194-B900-8FFD479FB7AD/L0/001

What I'd be interested in is native support for the above url scheme without having to do what @jagusiak says and convert to an assets-library:// scheme.

My specific use case (and reason for using a library that returns photos:// uris is that needed access to camera roll images that are stored in iCloud.

I'm using the React Native Photos Library library: https://github.com/olofd/react-native-photos-framework

onionsguru commented 5 years ago

Is there any other way to get the base64 data from an image file with uri starting with 'ph://' ? I think either using RNFS or ImageStore always results in "Error: ENOENT: no such file or directory, open 'ph://". On the other hand, these modules both support well to work with image files with uri starting with 'file://'.

MaxInMoon commented 5 years ago

readFile() fails only on iOS.

Is there an iOS way to? 1) get a working path from a selected image (uri starts with ph://), without replacing chars as stated here

2) or get a base64 from an uri?

Thank you in advance