How to set known length for R2 put?

The ReadableStream doesn't have a field for read/write length.
No description
9 Replies
chientrm
chientrmOP2y ago
I already put in the content-length headers 🤔 If I pass the ReadableStream from request.body it will upload successfully If I new ReadableStream manually, it'll throw the error.
kian
kian2y ago
you should use a FixedLengthStream if your creating your own
chientrm
chientrmOP2y ago
anyway I can get the length from the original ReadableStream?
kian
kian2y ago
Not without buffering it If it's from a request, just use request.body
chientrm
chientrmOP2y ago
I've read the first N bytes of request.body for the instruction description. The latter part of body is data as parameters for the instruction. How about, first fetch with the instruction body and the second fetch with data?
MrBBot
MrBBot2y ago
You should be able to get this from the Content-Length header on the request
chientrm
chientrmOP2y ago
I can't, on the other side I only got ReadableStream without the headers.
MrBBot
MrBBot2y ago
Isn’t the stream coming from request.body? Could you read that length, then subtract N for the data stream?
chientrm
chientrmOP2y ago
That sounds like it 👍

Did you find this page helpful?