0

This is my scenario:

I receive a base64 image and my goal is to upload a jpg to S3 through the Flysystem library. I'm on Symfony 3.3.9.

Actually I reiceive this error when I try to use the writeStream method.

ftell(): supplied resource is not a valid stream resource in /opt/project/vendor/league/flysystem/src/Util.php line 250

Here's my code

$data = explode(',', $base64String, 2);

$relativePath = 'here/there.jpg';

$imageDecoded = base64_decode($data[1]);

$imageResource = imagecreatefromstring($imageDecoded);

$s3FileSystem->writeStream($relativePath, $imageResource,
['visibility' => AdapterInterface::VISIBILITY_PUBLIC,
 'mimetype' => 'image/jpeg',
]);

Reading the docs of ftell() it says

The file pointer must be valid, and must point to a file successfully opened by fopen or popen.

How can I avoid this error? Should I save before the image to a file and after use fopen on it?

BTW I tried to save the image and it is correct, so no corrupt data.

stuzzo
  • 1,056
  • 1
  • 15
  • 36
  • The error is pretty clear. `imagecreatefromstring` creates a gd image resource, not a file handle. – deceze Oct 06 '17 at 15:07
  • Hi @deceze, so the only solution is save the resource to a file and after open it with fopen? – stuzzo Oct 06 '17 at 15:09
  • 1
    You could write to a `php://memory` stream too; or look for a method on `$s3FileSystem` that accepts a string, I don't know whether that exists. – deceze Oct 06 '17 at 15:10

0 Answers0