rn-fetch-blob
rn-fetch-blob copied to clipboard
bad base-64 fs.readStream
Info
"rn-fetch-blob": "^0.11.2",
"react-native": "^0.60.5",
platform: both
Issue:
Cant write file after it read from stream as base64
.
My test file is image (jpg)
YellowBox.js:71 Possible Unhandled Promise Rejection (id: 0):
Error: bad base-64
Error: bad base-64
at createErrorFromErrorData
What:
I want to read from stream as base64
string and save it to new file using fs.createFile
const { fs } = RNFetchBlob;
fs
.exists(file.image.path)
.then(exist => {
console.log('Send file socket exist', exist);
if (exist) {
console.log('index file exists');
fs
.readStream(file.image.path, 'base64', 102400)
.then(stream => {
stream.open();
let result = '';
stream.onData(chunk => {
result += chunk;
// console.log('Chunk', chunk);
// console.log('~~~~~~~~~~~~');
});
stream.onError(error => {
console.log('ERRRRORRRR');
console.log(error);
});
stream.onEnd(() => {
const dirs = RNFetchBlob.fs.dirs;
// .writeFile(
RNFetchBlob.fs
.createFile(
dirs.DownloadDir + '/tesssssssst.jpg',
result,
'base64'
)
.then(() => {});
});
})
.catch(err => {
console.log(err);
});
} else {
console.log('index file NOT exists');
}
})
.catch(err => {
console.log(err);
});