react-native-image-resizer
react-native-image-resizer copied to clipboard
output to base64 string
is this currently possible?
Not currently, but you can use a module like react-native-fs to read the output file that was created by react-native-image-resizer. See readFile method documentation. Beware of large files, it can be quite hazardous to store such files in a base64 string.
I did it the way you suggested but now for image resized and saved in
file:/data/data/com.app/cache/1472039430399.JPEG
I get following error in readFile:
Error: ENOENT: no such file or directory, open 'file:/data/data/com.app/cache/1472039430399.JPEG'(…)
is this path correct? file:/data/data/com.app/cache/1472039430399.JPEG
Not sure, you should double-check if the file is really on the device or not using for example the android tools in Android Studio :)
Maybe too late for you, but it can help others. storing local files on real devices will give dynamic document/caches directories. To find the correct app directory, us react-native-fs:
var RNFS = require('react-native-fs');
var filepath = RNFS.DocumentDirectoryPath + '/'+yourfilename;
var readfile = RNFS.readFile(filepath, 'utf8');
the 'DocumentDirectoryPath' will give you your current documentpath.
Any update?
If anyone runs into this, @virgial is mostly correct, although you need to use
var readfile = RNFS.readFile(filepath, 'base64')
instead of utf8.
https://github.com/itinance/react-native-fs/issues/417
Here's my working example:
const resizedImageUri = await ImageResizer.createResizedImage(
`data:image/jpeg;base64,${response.data}`,
400,
400,
"JPEG",
100,
0
);
const base64Data = await RNFS.readFile(
resizedImageUri.path,
"base64"
);
this.props.onPhotoUpload(`data:image/png;base64,${base64Data}`);
This works: 'data:image/jpeg,'+image The code expects a comma before the base64 image, for some reason...
@mickael-h Your solution is not suited for the question. You might be replying for 'how to upload base 64'
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed. Thank you for your contributions.