bad base-64 fs.readStream
See original GitHub issueInfo
"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);
});
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Top Results From Across the Web
fs.writeFile corrupt, using base64 string - node.js
The problem is that req.body.image contains a Data URL, which is more than just the image body. The base64 image data starts after...
Read more >Node.js v19.3.0 Documentation
When creating a Buffer from a string, this encoding will also correctly accept regular base64-encoded strings. When encoding a Buffer to a string,...
Read more >@zerobytellc/rn-fetch-blob - npm
This API creates a file stream, rather than convert entire data into BASE64 encoded string. It's handy when processing large files. When calling ......
Read more >Using the writeFileSync method in Node.js - LogRocket Blog
writeFileSync function can help you easily get started with the · writeFile function because they have similar parameters, and the only ...
Read more >Top 5 base64-arraybuffer Code Examples - Snyk
Learn more about how to use base64-arraybuffer, ... encoding: 'binary', }; const data = Buffer.from(base64.decode(saveFileReq.data)); fs.writeFile(save.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I changed the buffersize from 102400 to 102399 and it worked like magic! 102401 didn’t work but 102402 worked.
const stream = await RNFetchBlob.fs.readStream('(file path)', 'base64'); let fileContentsBuffer = Buffer.from('', 'base64'); await new Promise((resolve, reject) => { stream.onError(error => reject(error)); stream.open(); stream.onData(chunk => (fileContentsBuffer = Buffer.concat([fileContentsBuffer, Buffer.from(chunk, 'base64')]))); stream.onEnd(() => resolve()); });
try this. https://github.com/joltup/rn-fetch-blob/issues/315