Skip to content

Commit

Permalink
Refactor image saving to use arrayBuffer and Buffer.from()
Browse files Browse the repository at this point in the history
  • Loading branch information
bramses committed Mar 24, 2024
1 parent bbf7ff9 commit 34810d8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cloudflare-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ dotenv.config();
async function saveImgFromUrl(url) {
try {
const response = await fetch(url);
const buffer = await response.buffer();
const arrayBuffer = await response.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
// const buffer = await response.buffer();
const filename = `${Date.now()}.png`;
// await writing buffer to file
fs.writeFileSync(filename, buffer);
Expand Down

0 comments on commit 34810d8

Please sign in to comment.