robbiepaul / cloudconvert-laravel

A Laravel wrapper for the CloudConvert API
177 stars 34 forks source link

Can't pass converter options, results in a Guzzle exception #19

Closed gpmcadamold closed 8 years ago

gpmcadamold commented 8 years ago

When passing converter options as an array in the following way, Guzzle throws an exception.

$instance = CloudConvert::newInstance()
            ->file($from)
            ->withOptions($options)
            ->callback($callbackUrl)
            ->convert($to);

The exception is:

Invalid resource type: array

And it's occurring in at GuzzleHttp\Psr7\stream_for(array('resize' => '4000')) in MultipartStream.php line 87

Could it be related to this? https://github.com/guzzle/guzzle/issues/1079

Can you confirm that passing options as an array is still supported?

robbiepaul commented 8 years ago

I can't confirm, I haven't had a chance to look in to it, Guzzle 6 support was only added a week ago. If you can get away with using Guzzle 5 then do that. I'll have a look in to the issue further when I get a chance

robbiepaul commented 8 years ago

It was quite an easy one to fix. Just run composer update robbiep/cloudconvert-laravel

Just in case anyone else runs in to the same problem here was my fix:

If you upload a file with Guzzle 6 you have to send via ['multipart' => $mutlipartArray]

$mutlipartArray consists of an array of ['name' => 'fieldname', 'contents' => $contents] where $contents has to be one of: StreamInterface / resource / string, unfortunately not an array.

I just flattened the array, so $contents is always a string or a resource, so in my case the converteroptions section of $mutlipartArray now looks something like this ['name' => 'converteroptions[resize]', 'contents' => '4000']

See commit 0ae47d131962f33df73e6666f8c9745be64f7701