react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

I have to try to unlink to remove image but it storing in the pictures folder,

Open musadiq-jinbade opened this issue 6 years ago • 5 comments

I have to try to unlink to remove image but it storing in the pictures folder, please can #anyone advice

Originally posted by @musadiq-jinbade in https://github.com/itinance/react-native-fs/issues/352#issuecomment-597551732

musadiq-jinbade avatar Mar 11 '20 10:03 musadiq-jinbade

me too, @musadiq-jinbade have a solution

trugdn avatar May 19 '20 05:05 trugdn

try out this on

                    RNFS.exists(this.state.images)
                        .then((result) => {
                            if (result) {
                                return RNFS.unlink(RNFS.PicturesDirectoryPath)
                                    .then(() => {
                                        console.log('working',RNFS);
                                        return RNFS.unlink(RNFS.ExternalCachesDirectoryPath)
                                        .then(() => {
                                            console.log('error');
                                            return RNFS.unlink(RNFS.PicturesDirectoryPath)
                                        .then(() => {
                                            console.log('error');
                                        })
                                        .catch((err) => {
                                            console.log("error " + err.message);
                                        });  
                                        })
                                        .catch((err) => {
                                            console.log("error " + err.message);
                                        });                                        })
                                    .catch((err) => {
                                        console.log("error photo " + err.message);
                                    });
                            }
                        })
                        .catch((err) => {
                            console.log(err.message);
                        });

musadiq-jinbade avatar May 19 '20 05:05 musadiq-jinbade

I have done by this code, check and let me know

musadiq-jinbade avatar May 19 '20 05:05 musadiq-jinbade

In my case, I have my app album inside PicturesDirectoryPath and every time I capture images from camera, It saves the cropped image along with it. I have to delete every file with is not a directory (my app album folder) inside PicturesDirectoryPath after I saved it on my album by this code block

RNFS.readDir(RNFS.PicturesDirectoryPath).then(items => {
  items.forEach(item => {
    if (item.isFile()) {
      RNFS.unlink(
        `${RNFS.PicturesDirectoryPath}/${item.name}`
      );
    }
  });
});

maron-codersinteractive avatar May 27 '20 03:05 maron-codersinteractive

I had a similar task - take a photo and send it to server. The photo should NOT be stored in device memory. I used the react-native-community/react-native-image-picker.

RECIPE

  1. Take a new photo and store it in a separate folder, e.g. images.
  2. Copy the photo to the cache folder. This photo will be removed when the cache is cleaned.
  3. Remove the images folder via unlink, it works like in Linux rm -rf

CODE SNIPPET

const options = {
    title: 'Take Photo',
    cameraType: 'back',
    mediaType: 'photo',
    quality: 1,
    allowsEditing: false,
    noData: true,
    storageOptions: {
        skipBackup: true,
        path: 'images',
    },
};

const cameraPromise = new Promise((resolve) => {
    ImagePicker.launchCamera(options, async (response) => {
      	const getFileName = response.uri.split('/');
      	const fileName = getFileName[getFileName.length - 1];
      	const filePath = response.uri.split('//')[1];

      	await RNFS.copyFile(
        	filePath,
        	`${RNFS.CachesDirectoryPath}/${fileName}`
      	);

	    if (Platform.OS === 'ios') {
	        await RNFS.unlink(`${RNFS.DocumentDirectoryPath}/images`);
	    } else {
	        await RNFS.unlink(`${RNFS.PicturesDirectoryPath}/images`);
	    }

      	response.uri = `file://${RNFS.CachesDirectoryPath}/${fileName}`;

      	resolve(response);
    });
});

viktor-kurysh avatar Aug 05 '20 09:08 viktor-kurysh