Trying to delete images on android device. Works on iOS.
"react": "16.0.0-alpha.6",
"react-native": "0.44.0",
"react-native-fetch-blob": "0.10.5",
I can create and list files but unlink doesn't work. Added then() and catch(). 'file is deleted' is printed in the console.
Example path to delete
file:///data/user/0/se.myapp.name/files/selfie-1496323533962.jpg
Code used
var imageDir = (Platform.OS === 'ios') ? dirs.DocumentDir : 'file://' + dirs.DocumentDir;
RNFetchBlob.fs.unlink(imageDir + '/' + file)
.then(() => console.log("file is deleted"))
.catch(err => console.log("err", err))
Note: Running the delete in an array (multiple files that I want to delete)
@fbacker
In a group project I'm working on we tried to use the normalizePath-method (from RNFetchBlobFS.java) inside the unlink-method (from RNFetchBlobFS.java), just like I now see that even #389 suggests, and it worked.
I guess just like #389 suggests it should be applied in other methods too.
A quick and dirty work around for this is just to knock 'file://' off of the beginning of the file path.
dirty work around
Why is "file://" even there? I would not expect it. The method expects a path, and "file://" is not part of a path. I don't do any mobile development (it is purely accidental that I ended up contributing a tiny bit of code here) so I don't know if there's anything I'm missing about those platforms, but a URI is not a path.
Documentation for unlink: https://github.com/wkh237/react-native-fetch-blob/wiki/File-System-Access-API#unlinkpathstringpromise
If it works with "file://" removed I would not consider this an issue of RNFB.
I can create and list files but unlink doesn't work. Added then() and catch(). 'file is deleted' is printed in the console.
Can you try the 0.10.9 tree: https://github.com/wkh237/react-native-fetch-blob/tree/0.10.9
It should throw an error now, the code was updated.
Just FYI, the code to delete a file on Android, as you can see it has been extended to have better error reporting:
Sorry for late update. Been away on another project.
Upgraded to 0.10.8, WORKS PERFECT 馃憤
var imageDir = dirs.DocumentDir;
RNFetchBlob.fs.unlink(imageDir+'/'+file).then(() => { console.log("file is deleted") }).catch((err) => { console.log("err",err) })
Hi! there. I trying to delete on android device
Example path: /storage/emulated/0/Pictures/image-1dae47e4-6bf3-4370-a613-266f0c80412f.jpg
Code used
RNFetchBlob.fs.unlink(path).then(() => { console.log("Succeeded") }).catch((err) => { console.log("err",err) })
it also reports Succeeded, but the file is still there. How do I really delete the files?
Most helpful comment
Hi! there. I trying to delete on android device
Example path: /storage/emulated/0/Pictures/image-1dae47e4-6bf3-4370-a613-266f0c80412f.jpg
Code used
it also reports Succeeded, but the file is still there. How do I really delete the files?