Answer the question
In order to leave comments, you need to log in
Why does a written file from base64/Buffer fail?
I get the base64 representation of the file. I'm trying to write to a file. It can be pdf/docx/jpeg, whatever.
The recording is normal, but when you try to open it, an error appears that the file may be damaged or incorrectly recorded.
const docBuffer = Buffer.from(content[1].trim(), 'base64');
const stream = new Readable();
const writeStream = createWriteStream(
process.cwd()+'/file/'+name,
);
stream.push(docBuffer);
stream.push(null);
stream.pipe(writeStream);
Answer the question
In order to leave comments, you need to log in
const filePath = path.join(process.cwd(), "file", name)
fs.writeFile(filePath, base64, "base64", (err) => {
if (err) console.log(err)
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question