Skip to content
This repository was archived by the owner on Jul 16, 2021. It is now read-only.

Storage::put support Psr\Http\Message\StreamInterface #1252

Open
tjallingt opened this issue Jul 9, 2018 · 0 comments
Open

Storage::put support Psr\Http\Message\StreamInterface #1252

tjallingt opened this issue Jul 9, 2018 · 0 comments
Labels

Comments

@tjallingt
Copy link

I'm currently working with Guzzle and I noticed that Laravel Filesystem doesn't use streaming with classes implementing Psr\Http\Message\StreamInterface. At https://github.com/laravel/framework/blob/5.6/src/Illuminate/Filesystem/FilesystemAdapter.php#L164-L181 is_resource() will return false and thus Flysystem put will be called instead of putStream. Flysystem::put uses file_put_content() which AFAIK will implicitly cast to a string.

Currently the workaround is to detach the resource from the streaminterface:

$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'path/to/file');
$stream = $response->getBody();
$resource = $stream->detach();
Storage::put("path/to/file", $resource);
fclose($resource);

if Laravel handled the Psr7\Streaminterface I could write (and not worry about running out of memory):

$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'path/to/file');
Storage::put("path/to/file", $response->getBody());

Hope this makes sense and I'm not massively misunderstanding anything,
Cheers

Gman98ish added a commit to Gman98ish/framework that referenced this issue Oct 4, 2019
Gman98ish added a commit to Gman98ish/framework that referenced this issue Oct 4, 2019
Gman98ish added a commit to Gman98ish/framework that referenced this issue Oct 4, 2019
taylorotwell pushed a commit to laravel/framework that referenced this issue Oct 8, 2019
* Allow Storage::put to accept a Psr StreamInterface

Addresses: laravel/ideas#1252

* Moved psr/http-message to a suggested dependency

* Fixed error in filesystem composer.json
taylorotwell pushed a commit to illuminate/filesystem that referenced this issue Oct 8, 2019
* Allow Storage::put to accept a Psr StreamInterface

Addresses: laravel/ideas#1252

* Moved psr/http-message to a suggested dependency

* Fixed error in filesystem composer.json
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants