How do I add an entry to a Google cloud storage file from an application?

This legacy API supports adding content to the Google Cloud Storage file:

FileWriteChannel FileService.openWriteChannel(AppEngineFile file, boolean lock) 

But,

 GcsOutputChannel GcsService.createOrReplace(GcsFilename filename, GcsFileOptions options) 

doesn't look like that.

What is the solution here?

+7
google-app-engine google-cloud-storage
source share
2 answers

Sorry to have been informed, but this cannot be done without replacing the file every time.

As indicated in Cloud Services Documents under Object Continuity

Objects are immutable, which means that the loaded object cannot be changed during the entire period of its storage. Object storage lifetime is the time between successful creation of an object (upload) and successful removal of an object. In practice, this means that you cannot make incremental changes to objects, such as add operations or truncate operations. However, you can overwrite objects stored in Google Cloud Storage, since the rewrite operation is an action of the delete object that is immediately performed by the upload operation of the object. Thus, a single rewrite operation simply marks the end of one unchanging lifetime of the object and the beginning of a new unchanging lifetime of the object.

+7
source share

While Google’s cloud storage objects are immutable, something you need to help if you need to limit the addition is to create you: create an object

This operation basically combines the contents of several objects in the same bucket under a new name, for example cat file1 file2 > newfile , but without cat file1 file2 > newfile data.

So, you can create a new object, load the contents to add to it, close and then compose this new fragment at the end of your main file.

There is a caution: no more than 1024 "pieces" per object are permissible, and component objects that are themselves composed are taken into account as constituent source parts (therefore, you cannot deceive the limit by re-compiling).

+5
source share

All Articles