How to set known length for R2 put?

The ReadableStream doesn't have a field for read/write length.
No description
9 Replies
chientrm
chientrmOP17mo 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
kian17mo ago
you should use a FixedLengthStream if your creating your own
chientrm
chientrmOP17mo ago
anyway I can get the length from the original ReadableStream?
kian
kian17mo ago
Not without buffering it If it's from a request, just use request.body
chientrm
chientrmOP17mo 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
MrBBot17mo ago
You should be able to get this from the Content-Length header on the request
chientrm
chientrmOP17mo ago
I can't, on the other side I only got ReadableStream without the headers.
MrBBot
MrBBot17mo ago
Isn’t the stream coming from request.body? Could you read that length, then subtract N for the data stream?
chientrm
chientrmOP17mo ago
That sounds like it 👍
Want results from more Discord servers?
Add your server