Transform user-uploaded images before up...

Wanted to ask in #images but that channel is archived. It seems the code from the CF Images docs is out-of-date? https://developers.cloudflare.com/images/tutorials/optimize-user-uploaded-image/#5-upload-to-r2 1. The binding's input()-function takes only a ReadableStream, not an ArrayBuffer. 2. The resulting image ReadableStream (res.image() or res.response().body doesn't have a fixed length, therefore can't directly save to R2: "Provided readable stream must have a known length (request/response body or readable half of FixedLengthStream)" I have to transform with FixedLengthStream before sending to IMAGES binding and afterwards which makes it quite cumbersome. Is this intended? It doesn't match the docs.
Cloudflare Docs
Transform user-uploaded images before uploading to R2
Set up bindings to connect Images, R2, and Assets to your Worker
1 Reply
Anton
AntonOP3w ago
DEBUG res {
res: TransformationResultImpl {},
type: 'image/jpeg',
image: ReadableStream {
locked: false,
[state]: 'readable',
[supportsBYOB]: true,
[length]: undefined
}
}
DEBUG res {
res: TransformationResultImpl {},
type: 'image/jpeg',
image: ReadableStream {
locked: false,
[state]: 'readable',
[supportsBYOB]: true,
[length]: undefined
}
}
-> resulting ReadableStream has undefined length.

Did you find this page helpful?