Reputation: 1659
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.
Upvotes: 15
Views: 15926
Reputation: 5
Blockquote 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.
In my case this was the solution, however I wasted a lot of time since the RNFetchBlob?.fs.write() function kept returning the error. The strangest thing is that when exploring the device's files, the files were being saved correctly despite receiving this error in the console.
Upvotes: 0
Reputation: 51
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);
Upvotes: 2
Reputation: 28539
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 sharingLSSupportsOpeningDocumentsInPlace
: Supports opening documents in placeThis will allow your DocumentsDirectory
to be opened in iTunes and it should also allow you to share your files via the Files
application.
You can read more about LSSupportsOpeningDocumentsInPlace
here
In iOS 11 and later, if both this key and the
UIFileSharingEnabled
key areYES
, the local file provider grants access to all the documents in the app’sDocuments
directory. These documents appear in theFiles
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.
Upvotes: 43