Write to R2 with ReadableStream
Im trying to write a ReadableStream to R2, however, I cannot pass a stream to the r2
.put
without giving it a fixed size first, so I am piping an email objects stream to a FixedLengthStream
as so:
and then saving it to R2 as follows:
Im seeing the entry identifier
in my R2 bucket, however the content is empty. message.rawSize
is showing the number of bytes I would expect.
Am I using the stream pipes wrong?
Thank you3 Replies
it's possible to use a readable stream in the put request. your code looks correct but I would check if message is correctly implementing the streaming interface. I assume message.raw is a readbleStream so try to use that in a basic handler like return new Request(readable,{headers}) and see if you are getting something back
message is an EmailObject that is getting passed to the email worker. Logging the raw size gives me the number of bytes I expect.
I can read the stream into a string using a loop and I get what I ekpect, but passing the stream directly as above is giving me zero bytes in R2
I have yet to use the email handler so I'm not sure what an EmailObject is supposed to be. Have you tried creating a dummy stream and passing that to r2?
I can attest that it's possible to use a stream as I have been doing it to transfer data from ftp using the tcp socket api.
If you are willing to share your code maybe I can have a closer look