Access the main Google Cloud Storage object from GAE createUploadUrl

I am trying to save uploads of user photos to Google Cloud Storage, but ran into call problems:

blobStoreService.createUploadUrl(...) 

I need to keep track of which user ID is associated with the downloaded file. If the user ID is 1234, I need to save this as metadata in the Cloud Storage file.

I can add metadata when I create the cloud storage file directly:

 GSFileOptionsBuilder optionsBuilder = new GSFileOptionsBuilder() .setBucket("myBucket") .setKey(key) // path... .addUserMetadata("userId", "1234"); 

But I really want to use GAE provided that BlobStoreService.createUploadUrl (...), because it supports files of a larger size than this code can handle. Is it possible to specify metadata at all using createUploadUrl? Or can you even find out which google storage key / name is created?


Update I already have blobKey from serlvet server callback. However, I cannot find a way to add metadata to the Google storage file associated with this blobKey. At least locally, he thinks this is a BlobStore entry, not a GS file

  // get the key: Map<String, List<BlobKey>> blobKeysFromPost=BlobstoreServiceFactory.getBlobstoreService().getUploads(request); // pull out the blobKey generated from the recently submitted POST BlobKey blobKey = ... // Now how do I access the cloud storage entry for this key? I tried: AppEngineFile file = FileServiceFactory.getFileService().getBlobFile(blobKey); // But this file locally returns "blobstore": file.getFileSystem().getName(); // Should be GS. 
+4
source share
2 answers

I think this is a bug that files are uploaded to Google Storage for BlobKeys that say they are in BlobStore. Without knowing the generated file name, we cannot interact with the downloaded file in GS. For example, we cannot add metadata to a file, change ACLs, delete, etc.

I discovered this problem in the GAE tracker: http://code.google.com/p/googleappengine/issues/detail?id=8337

+1
source

From the docs:

When the user submits the form, the POST is processed by the Blobstore API, which creates the blob. The API also creates an information record for blob and saves the record in the data store and passes the rewritten request to your application at the specified path in the form of a blob key:

https://developers.google.com/appengine/docs/java/blobstore/overview#Uploading_a_Blob

So, once it is downloaded, you will get a blob key that you can save and add metadata. I know only about Python, but AFAIK you do not need to add such metadata to the blobstore object, you have to track it yourself.

0
source

Source: https://habr.com/ru/post/1441959/


All Articles