Reputation: 28374
I'm using http.request
to download JPEG file. I am then using fs.writeFile
to try to write the JPEG file out to the hard drive.
None of my JPEG files can be opened, they all show an error (but they do have a file size). I have tried all of the different encodings with fs.writeFile
.
What am I messing up in this process?
Here's what the working one is showing when viewing it raw:
And here is what the bad one using fs.writeFile is showing:
Upvotes: 0
Views: 1888
Reputation: 1
Thank you, looking to the previous response, I was able to save de media correctly:
fs.writeFile(
filepath + fileName + extension,
mediaReceived, // to use with writeFile
{ encoding: "binary" }, // to use with writeFile ***************WORKING
(err) => {
if (err) {
console.log("An error ocurred while writing the media file.");
return console.log(err);
}
}
);
Upvotes: 0
Reputation: 28374
Figured it out, needed to use res.setEncoding('binary');
on my http.request
.
Upvotes: 1