amphp / http-client

An advanced async HTTP client library for PHP, enabling efficient, non-blocking, and concurrent requests and responses.
https://amphp.org/http-client
MIT License
704 stars 66 forks source link

I want to pass ReadableStream to FileBody #315

Closed PhantomArt closed 1 year ago

PhantomArt commented 1 year ago

In my code, I have the content of the file as a ReadableStream. I would like to create a FileBody from this ReadableStream. Right now I have two ways:

  1. Save ReadableStream to a file on disk, then pass it to FileBody.
  2. Read ReadableStream into a variable and pass it to FileBody.

It seems to me that both options are not optimal. FileBody is essentially an intermediary to supply a ReadableStream using the createBodyStream() method, so why isn't it possible to pass a ReadableStream directly to FileBody?

PhantomArt commented 1 year ago

I think I came up with a better version. You can create a FormBody::addFileFromStream() method that takes a StreamBody as an argument, similar to the FormBody::addFileFromString() method.

kelunik commented 1 year ago

This will be possible in 5.x, see #322.