简体   繁体   中英

How to modify a Google Cloud Storage object using Python client library?

I'm trying to set up a cloud function that performs user authentication. I need it to open an object stored in a Cloud Storage bucket, read its content and verify if username and password match those coming from the HTTP request.

In some cases the function needs to add a user: it should retrieve the content of the.json file stored in the bucket, add a username:password pair and save the content in the same object.Basically, it has to modify the content of the object .

I can't find the way o do it using the Cloud Storage Python client library. None of the tutorials listed in the GitHub pages mentions anything like "modify a file" or similar concepts (at least in their short descriptions). I also looked for a method to perform this operation in the Blob class source code, but I couldn't find it.

Am I missing something? This looks to me as a very common operation, one that should have a very straightforward method, like blob.modify(new_content) .

I have to confess that I am completely new to GCP, so there is probably an obvious reason behind this (or maybe I just missed it).

Thank you in advance!

Cloud Storage is a blob storage and you can only read, write and delete the object. You can't update the content (only the metadata) and can't move/rename a file (move and rename operation perform a copy (create a new object) followed by a delete (of the old object)).

In addition, the directories don't exist, all the file are put at the root level of the bucket. The file name contains the path from the root to the leaf. The / is only a human representation for the folders (and the UI use that representation), but the directories are only virtual.

Finally, you can't search on a file suffix, only per prefix of the file name (including the full path from the root path / )


In summary, it's not a file system, it's a blob storage. Change your design or your file storage option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM