Superbalist / flysystem-google-cloud-storage

Flysystem Adapter for Google Cloud Storage
MIT License
265 stars 105 forks source link

PHP Warning thrown after asset Uploaded - stream provided gets corrupted #95

Closed obj63mc closed 5 years ago

obj63mc commented 5 years ago

Currently I have a site that uploads a file stored in the temp directory of the server. This is a path like - "/private/var/tmp/phprROvf6"

Then we open that path, and then try to upload it GC. Example

        $handle = fopen($path, 'r');
        if ($handle === false) {
            throw new InvalidArgumentException("$path could not be opened for reading");
        }
        $result = $filesystem->putStream($fileID, $handle);

        fclose($handle);

        return $result;

The issue is whenever it tries to close the $handle variable after uploading it states it is no longer a stream and errors out. I can confirm that the handle is a stream originally, that the file does upload correctly and the result returned says true, but after it gets uploaded - https://github.com/Superbalist/flysystem-google-cloud-storage/blob/master/src/GoogleStorageAdapter.php line 174 (protected function upload($path, $contents, Config $config)

   $object = $this->bucket->upload($contents, $options);

the stream then becomes corrupt.

var_dump($handle) before it tries to upload -

    resource(13) of type (stream)

var_dump($handle) after the stream is uploaded -

   resource(13) of type (Unknown)

Any idea why this would happen or how to prevent it.

obj63mc commented 5 years ago

Looks like this more an issue with Guzzle PSR7 auto removing resources that were in the temp directory upon upload. Still if you have any other thoughts on why the temp resources is deleted automatically would be great. Can't find anything out there on this.