I have a generated bitmap that I can write to disk using Jimp, and I can verify it is properly formatted. However, using the few simple lines provided by Vercel, I can't seem to get this image uploaded properly to blob storage from my Next.js API endpoint.
The dashboard says it is 1.15 MB. The version that is written to disk is 1.126 according to my file explorer. That seems off. Either way, when I go to download the image from Vercel blob storage, the download ends up being 0B.
I figure this has something to do with the way I am streaming the file to the storage endpoint. I suspect I am not using the right data type or am unintentionally including data other than the raw bytes of my image. It's hard to troubleshoot when the result is 0 B though!
Here is what the code in question. I hitting my API endpoint to trigger it when running the app with npm run dev:
import { Jimp } from "jimp";
import { put } from "@vercel/blob";
import { JimpMime } from "jimp"
export async function GET(request) {
let screenshot = await take_screenshot()
const image = await Jimp.read(screenshot)
image.greyscale()
const buffer = await image.getBuffer(JimpMime.bmp);
console.log(buffer)
/* The console logs this, which seems right?
*/
await image.write('test.bmp') //this image is formatted correctly and displays fine
const { url } = await put('dashboard.bmp', buffer, { access: 'public', contentType: "image/bmp", allowOverwrite: true});
return new Response({})
}
What am I missing here? Thanks!