spatie / laravel-google-cloud-storage

Google Cloud Storage filesystem driver for Laravel
https://spatie.be/open-source
MIT License
196 stars 51 forks source link

URL generation seems broken #22

Closed Tarpsvo closed 2 years ago

Tarpsvo commented 2 years ago

After updating this package and its dependencies, it seems that the storage_api_url was changed to apiEndpoint and that the the URI should no longer contain the bucket name directly, as the new API seems to use /b/{bucketName}/o/{objectPath} which does not work when there's a prefixed bucket name as well.

When I try to upload a file with apiEndpoint as https://storage.googleapis.com/my-bucket, I will receive a NotFoundException as the endpoint /bucket-name/b/bucket-name/o/path-to-file returns a No such object error from Google.

However, the same request to path /b/bucket-name/o/path-to-file works (note the missing bucket-name prefix).

So I re-configured my setup so that the apiEndpoint is https://storage.googleapis.com/ instead of https://storage.googleapis.com/bucket-name.

This makes the uploading of files work, but the URL generation seems to be broken.

See this code:

https://github.com/spatie/laravel-google-cloud-storage/blob/cee6e6d1d92ca7bd293816ff234371be692b1951/src/GoogleCloudStorageAdapter.php#L39-L48

Line 41 creates a correct URL for the file: https://storage.googleapis.com/bucket-name, however line 44 will overwrite it with https://storage.googleapis.com/. The overall result is that the bucket name goes missing and the file URL will end up as https://storage.googleapis.com/path-to/my-file.png instead of the expected https://storage.googleapis.com/bucket-name/path-to/my-file.png.

What am I doing wrong here? What else has changed?

PS: Everything works perfectly in version 2.0.2.

Thank you!

spatie-bot commented 2 years ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.