google-apis-rs / google-cloud-rs

Asynchronous Rust bindings for Google Cloud Platform APIs.
176 stars 48 forks source link

Storage: Object.get() does not work with object names containing "/" #32

Closed floridoo closed 3 years ago

floridoo commented 3 years ago

For example:

let mut file = bucket.object("test/test.txt").await?;
let data = file.get().await?;

does result in HTTP error: HTTP status client error (404 Not Found) for url (https://storage.googleapis.com/storage/v1/b/xxx/o/test/test.txt).

Possible solution: Does the object name need to be url-encoded?

Hirevo commented 3 years ago

Hello !

Sorry for my long absence.
I looked into it and I am actually confused.
The object naming guidelines from GCP are saying that forward slashes are legal to use, but when attempting to rename an object using the GCP console, it gives the following error:

image

The error message is weird because it sounds like its saying that slashes are not legal, but maybe it is just a limitation of the GCP console ?

Hirevo commented 3 years ago

I am sorry, I misunderstood the usage of slashes in object names.

As far as GCS is concerned, slashes are just part of the name, and nothing else, as expected.
But the GCS section of the GCP console tries to interpret the slashes as folders and its rename operation tries to maintain its 'virtual folder location' by forbidding slashes.

I also looked a bit at the code for the Go GCS client and they are indeed percent-encoding these values.

Adding percent-encoding locally did fix this issue, so I'll be pushing a PR shortly for it.
This issue seems to only affect the storage client in google-cloud-rs because it is the only service where we use an HTTP client instead of a gRPC one.

Thanks for reporting the issue, and sorry again for the delay.

floridoo commented 3 years ago

Thank you for taking the time to fix this!