[Support] GuzzleHttp\Psr7\Stream vs Gotenberg\Stream
Closed this issue ยท 2 comments
Greetings!
I am sorry to pollute your ticket stream with a support request. ๐
โ
I have successfully implemented the gotenberg (v7) docker image and this library into my Symfony-based project.
โ
I have successfully "merged" its use with FlySystem via the OneupFlysystemBundle
โ
I am successfully producing merged pdfs from sources of html & office docs and storing them to AWS/S3 via the AwsS3 Flysystem adapter!
So all, in all, I am quite happy with the end product. I have one kludgy bit however, which I wondered if you might assist me.
Flysystem works well with Streams. But not directly with your Stream class. Therefore I end up doing something like this several times in my project:
use Gotenberg\Stream;
use GuzzleHttp\Psr7\Stream as Psr7Stream;
....
$streams = [];
foreach ($mountPaths as $mountPath) {
$psr7Stream = new Psr7Stream($this->mountManager->readStream($mountPath));
$streams[] = new Stream('file.pdf', $psr7Stream);
}
$request = $this->gotenberg->pdfEngines()
->outputFilename($destination)
->merge(...$streams);
(my gotenberg
instance above is simply a wrapper of yours in order to include other services with DI)
You can see the gymnastics I am doing to first create the Psr7Stream (readStream
returns a resource
), then secondly create an instead of Stream
.
Is there a cleaner way to do this? Can I create a Gotenberg/Stream
directly from a resource or handle this differently?
Secondly, I'd like to write a stream directly from the response. Currently I do this:
$response = $this->send($request, $client);
...
$this->mountManager->write($mountPath.$filename, $response->getBody()->getContents());
I'd prefer to use Flysystem's writeStream
method here if possible, Is it possible to get a Stream from the response?
As I said, I apologize in advance for the support request. I'm sure you're rolling your eyes at my stupidity ๐ ๐คฃ . Thanks in advance! ๐
Hello @craigh ๐
I'm not familiar enough with FlySystem to give you in depth support about what you're doing ๐
That being said, I see nothing wrong with the way you're creating Stream
. Maybe we could add a static method Stream::fromResource
but I'm not sure it that's worth it.
If you want to write a stream directly from the response, I guess you're best option is to use you own client to send the PSR7 request ๐
Have fun!
Thank you.