Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native fs iOS not showing files in the document directory

I am working on a react native project. I need to store the captured images in the custom folder.

I am using react native fs library for that. I am able to create the image in the desired directory but I am not able to see those images in my iphones' file directory.

Here is my code I am using to store the images.

 async moveAttachment(capturedImagePath) {

    $filePathDir = `${RNFS.DocumentDirectoryPath}/myapp/myfilename`;
    $filePath = `${$filePathDir }/myfilename.png`;
    return new Promise((resolve, reject) => {
        RNFS.mkdir(filePathDir)
        .then(() => {
            RNFS.moveFile(capturedImagePath, filePath )
            .then(() => resolve(dirPictures))
            .catch(error => reject(error));
        })
        .catch(err => reject(err));
    });
}

I am able to see the image in my simulator's document directory but not able to see in the iPhone > files directory.

Please help me to figure this out.

like image 573
Pankaj Agrawal Avatar asked Jan 20 '26 11:01

Pankaj Agrawal


2 Answers

You should be able to enable it by updating your Info.plist. You need to add two keys:

UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace should both be added and set to YES.

  • UIFileSharingEnabled: Application supports iTunes file sharing
  • LSSupportsOpeningDocumentsInPlace: Supports opening documents in place

This will allow your DocumentsDirectory to be opened in iTunes and it should also allow you to share your files via the Files application.

info.plist

You can read more about LSSupportsOpeningDocumentsInPlace here

In iOS 11 and later, if both this key and the UIFileSharingEnabled key are YES, the local file provider grants access to all the documents in the app’s Documents directory. These documents appear in the Files app, and in a document browser. Users can open and edit these document in place.

Note that any item you save in the Documents directory will be accessible.

like image 114
Andrew Avatar answered Jan 23 '26 08:01

Andrew


The answer @Andrew provided still working on iOS 17 Remember only to set the Directory to the right place const basePath = (Platform.OS === 'android' ? RNFS.DownloadDirectoryPath : RNFS.DocumentDirectoryPath);

like image 36
Mauro J. Mendonça Júnior Avatar answered Jan 23 '26 10:01

Mauro J. Mendonça Júnior



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!