0

这是我的场景:

我收到一个 base64 图像,我的目标是通过Flysystem库将 jpg 上传到 S3 。我在 Symfony 3.3.9 上。

实际上,当我尝试使用 writeStream 方法时,我收到了这个错误。

ftell():提供的资源不是 /opt/project/vendor/league/flysystem/src/Util.php 第 250 行中的有效流资源

这是我的代码

$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',
]);

阅读它说的 ftell() 的文档

文件指针必须有效,并且必须指向一个被 fopen 或 popen 成功打开的文件。

我怎样才能避免这个错误?我应该在将图像保存到文件之前并在使用 fopen 之后保存它吗?

顺便说一句,我试图保存图像并且它是正确的,所以没有损坏的数据。

4

0 回答 0