React-native-fs: My DocumentDirectoryPath returns /data/data

Created on 11 Jul 2016  Â·  4Comments  Â·  Source: itinance/react-native-fs

/data/data/org.missingmaps.mapswipe/files

Instead of /Android/data/org.missingmaps.mapswipe/files

How should I go about fixing this? :-)

Cheers

Most helpful comment

RIP @PimDeWitte ... he never made it back to his pc to close this issue ;)

BTW just to clarify the issue for anyone else, /data/data/ isn't a bug thats a real file path on the device. Also when saving a file do it like so:

/* /data/data/com.app.bundleId/cache/9c4bb804-df80-4fec-bc76-3b2de49f06b8.png */
const uri = `${RNFS.CachesDirectoryPath}/${uuid.v4()}.png`;
await RNFS.writeFile(uri, b64, 'base64');

And if you need to access the file again, say upload the file with fetch, you will need to prepend the uri with file://

Also another big gotcha for me was that a base-64 string prepended with data:image/png;base64, is considered a malformed and will be written to file as 0 bytes but otherwise look like it'll succeed (atleast on iOS).

^^^^^ IMO the documentation should be updated with the above explanation ^^^^^

All 4 comments

why do you need it to be /Android/data/org.missingmaps.mapswipe/files?
Isn't it enough that you get a directory where you can store and accept your files?

I already got it. I was just missing the file://. Will close when I get to
pc
On Sun, Jul 10, 2016 at 9:13 PM xitaoque [email protected] wrote:

why do you need it to be /Android/data/org.missingmaps.mapswipe/files?
Isn't it enough that you get a directory where you can store and accept
your files?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/johanneslumpe/react-native-fs/issues/135#issuecomment-231638604,
or mute the thread
https://github.com/notifications/unsubscribe/AIW4jkAHkKNiSImzwBS-7XQZS3kKLZQLks5qUcLLgaJpZM4JI9ef
.

RIP @PimDeWitte ... he never made it back to his pc to close this issue ;)

BTW just to clarify the issue for anyone else, /data/data/ isn't a bug thats a real file path on the device. Also when saving a file do it like so:

/* /data/data/com.app.bundleId/cache/9c4bb804-df80-4fec-bc76-3b2de49f06b8.png */
const uri = `${RNFS.CachesDirectoryPath}/${uuid.v4()}.png`;
await RNFS.writeFile(uri, b64, 'base64');

And if you need to access the file again, say upload the file with fetch, you will need to prepend the uri with file://

Also another big gotcha for me was that a base-64 string prepended with data:image/png;base64, is considered a malformed and will be written to file as 0 bytes but otherwise look like it'll succeed (atleast on iOS).

^^^^^ IMO the documentation should be updated with the above explanation ^^^^^

Sorry, the file:// fixed it!!
On Fri, Aug 12, 2016 at 9:42 AM Jonathan Stanton [email protected]
wrote:

RIP @PimDeWitte https://github.com/PimDeWitte ... he never made it back
to his pc to close this issue ;)

BTW just to clarify the issue for anyone else, /data/data/ isn't a bug
thats a real file path on the device. Also when saving a file do it like so:

/* /data/data/com.app.bundleId/cache/9c4bb804-df80-4fec-bc76-3b2de49f06b8.png */const uri = ${RNFS.CachesDirectoryPath}/${uuid.v4()}.png;await RNFS.writeFile(uri, b64, 'base64');

And if you need to access the file again, say upload the file with fetch,
you will need to prepend the uri with file://

Also another big gotcha for me was that a base-64 string prepended with
data:image/png;base64, is considered a malformed and will be written to
file as 0 bytes but otherwise look like it'll succeed (atleast on iOS).

^^^^^ IMO the documentation should be updated with the above explanation
^^^^^

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/johanneslumpe/react-native-fs/issues/135#issuecomment-239496844,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AIW4jlAphUNrD6hWXT5f5xm_vqmChHldks5qfKJvgaJpZM4JI9ef
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MuppaAkhil picture MuppaAkhil  Â·  3Comments

let-aurn picture let-aurn  Â·  3Comments

duckmyanmar picture duckmyanmar  Â·  3Comments

barnir picture barnir  Â·  3Comments

opoze picture opoze  Â·  3Comments