Skip to content

Commit

Permalink
Fix image downloading in _imgProcessor.js
Browse files Browse the repository at this point in the history
  • Loading branch information
asadm committed Apr 12, 2024
1 parent b72ccac commit 720a8c2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/pages/api/_imgProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ export async function processMarkdownWithImages(filePath, imgDirName, imagesBase
const contentType = res.headers.get("content-type");
// const extension = contentType.split("/")[1];
console.log(`Downloading: ${url} to ${destImagePath}`);
const dest = fs.createWriteStream(destImagePath);
await res.body.pipe(dest);
await new Promise((res, rej) => {
dest.on("finish", res);
});
const buffer = await res.arrayBuffer();

fs.writeFileSync(destImagePath, Buffer.from(buffer), "binary");

// const dest = fs.createWriteStream(destImagePath);
// await res.body.pipe(dest);
// await new Promise((res, rej) => {
// dest.on("finish", res);
// });
if (imagesBasePathOverride){
return match.replace(url, `${imagesBasePathOverride}${imgName}`)
}
Expand Down

0 comments on commit 720a8c2

Please sign in to comment.