-
Notifications
You must be signed in to change notification settings - Fork 237
Open
Description
An example would be great in the docs that shows how to stream the result to s3 and get the correct content type for the image. I am correctly creating a Buffer and using that. But it would be great if I could stream the result.
My bad code:
export async function getBuffer(
result: FileOutput
): Promise<Uint8Array<ArrayBuffer>> {
const blob = await result.blob()
const arrayBuffer = await blob.arrayBuffer()
const buffer = new Uint8Array(arrayBuffer)
return buffer
}
export async function getContentType(
buffer: Uint8Array<ArrayBuffer>
): Promise<string> {
if (buffer.length < 4)
throw new Error('Content type not found: buffer.length < 4')
// JPEG: starts with FF D8 FF
if (buffer[0] === 0xff && buffer[1] === 0xd8 && buffer[2] === 0xff)
return 'image/jpeg'
//..............
}
const command = new PutObjectCommand({
Bucket: ...,
Key: ...,
Body: buffer,
ContentType:contentType,
})
Metadata
Metadata
Assignees
Labels
No labels