alpha0010 / react-native-file-access

Filesystem access for React Native
MIT License
298 stars 18 forks source link

Can this library write/upload media file like image, video? #58

Closed Parkjunwu closed 1 year ago

Parkjunwu commented 1 year ago

Hello!

I want to implement that user's local file or fetched file upload to application's local storage like android's scoped storage.

But I don't know well about upload to local storage.

I understand this library's documentation explanation like this library can only upload .txt file.

I want to know my understanding is right.

Can I upload media file to local storage like image, video file?

Thank you!

alpha0010 commented 1 year ago

On Android, the following should copy an image to the system image storage.

// Produce an image file somehow, storing here:
const source = Dirs.CacheDir + '/img.jpg';

await FileSystem.cpExternal(source, 'img.jpg', 'images');

If you want more control over the destination, you could do something like:

import * as ScopedStorage from 'react-native-scoped-storage';

const targetDir = await ScopedStorage.openDocumentTree();
const target = AndroidScoped.appendPath(targetDir, 'img.jpg');
await FileSystem.cp(source, target);
Parkjunwu commented 1 year ago

Thank you for your comment!

Is this process also working right on IOS?

alpha0010 commented 1 year ago

iOS has a different permissions model, which I unfortunately do not understand very well (when I have time, I plan to investigate further). Currently the way this library works, putting files in Dirs.DocumentDir, and enabling UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace, will allow other apps to read files from this app.

From the documentation, https://github.com/react-native-cameraroll/react-native-cameraroll might be able to do what you intend.

Parkjunwu commented 1 year ago

Thank you very much!!