ioswebviewfilesystems

Where are pictures saved when opening the camera from iOS webview?


I have a react native app which uses react-native-webview 13.10.3 (which uses WKWebview on iOS). Sometimes the page in the webview contains an <input type="file"> which, on click, shows a dialog for selecting a file. One of the options in this dialog is "Take Photo or Video" which brings up the camera to take a new picture. The camera goes away after taking a picture, and the <input> gets updated with the details of the newly created image file.

Whenever I go through this process, I notice the size of my app's "Documents & Data" (in Settings > General > Storage > [My App]) increasing by a few MB - about the size of the image file, I believe. I would like to delete these image files once they are no longer needed in order to keep my app from consuming more and more storage space.

I have read about "Download Container..." available in Xcode > Window > Devices and Simulators. I looked through my app's container, but I didn't notice any image files.


Solution

  • Temporary files must have been created when you used <input type="file">. I suggest you use react-native-fs library to locate and delete the temp files after the processing is completed or no longer needed.

    Like this:

    import RNFS from 'react-native-fs';
    
    const deleteTemporaryFiles = async () => {
        try {
            const tempDir = RNFS.TemporaryDirectoryPath;
    
            const files = await RNFS.readDir(tempDir);
    
            for (const file of files) {
              await RNFS.unlink(file.path);
            }
    
            console.log('Temporary files deleted successfully');
        } catch (error) {
            console.error('Error deleting temporary files:', error);
        }
    };
    
    deleteTemporaryFiles();