diff --git a/vendor/magento/module-aws-s3/Driver/AwsS3.php b/vendor/magento/module-aws-s3/Driver/AwsS3.php index 76e3e2fc333f..82707aa52451 100644 --- a/vendor/magento/module-aws-s3/Driver/AwsS3.php +++ b/vendor/magento/module-aws-s3/Driver/AwsS3.php @@ -857,15 +857,21 @@ public function fileWrite($resource, $data) */ public function fileClose($resource): bool { + if (!is_resource($resource)) { + return false; + } //phpcs:disable - $resourcePath = stream_get_meta_data($resource)['uri']; + $meta = stream_get_meta_data($resource); //phpcs:enable foreach ($this->streams as $path => $stream) { // phpcs:ignore - if (stream_get_meta_data($stream)['uri'] === $resourcePath) { + if (stream_get_meta_data($stream)['uri'] === $meta['uri']) { + if (isset($meta['seekable']) && $meta['seekable']) { + // rewind the file pointer to make sure the full content of the file is saved + $this->fileSeek($resource, 0); + } $this->adapter->writeStream($path, $resource, new Config(self::CONFIG)); - // Remove path from streams after unset($this->streams[$path]);