[PYTHON] URL encoding process in GAE / py's Cloud Storage library

(This is a memo about python of GAE 1gen that I wrote a long time ago, but I will drop it because it is in the draft. I think that it is unnecessary because GAE 2gen is the mainstream now)

When referencing GCS from GAE / py, there is a case of a file name that requires URL encoding, so I was a little addicted to it, so make a note of it. In addition, this problem is not a problem when you touch REST API etc. by yourself, it is just a story that the quote processing of cloudstorage library for GAE was not consistent.

Cloud Storage Client Library for App Engine

The App Engine documentation refers to a library called the Google Cloud Storage Client Library ().

The name is inconsistent, pip install GoogleAppEngineCloudStorageClient It is a library that can be used.

The repository name on github is appengine-gcs-client, so this name may be correct. It seems that there are one for java and one for python, but this time we are talking about the library for python.

As a feature, I think it's a file-like wrapping interface that uses App Engine credentials to access Cloud Storage's REST API.

Only src of copy2 method does not URL encode

The only thing that got stuck this time was that the request was not made according to the REST API specifications. This was because there was a part where URL quote processing was omitted in the implementation of client library.

I was addicted to the copy2 (src, dst) method, which src is URL-encoded. Even though it didn't work, the strings passed to other methods and dst were URL-encoded.

The reason is simple: the other arguments are mostly passed as path parameters, so ʻurllib.quote () processing is written, whereas The src of the copy2 method is the REST API header parameter [x-goog-copy-source](https://cloud.google.com/storage/docs/xml-api/reference-headers?hl=ja#xgoogcopy) Because it was passed as ʻurllib.quote () processing was not written.

Recommended Posts

URL encoding process in GAE / py's Cloud Storage library
Get Google Cloud Storage object list in Java
Image URL is blank in GAE & GCS & Django