brariden
brariden

Reputation: 124

Accessing the underlying Google Cloud Storage object from GAE createUploadUrl

I am trying to store user photo uploads in Google Cloud Storage but running into issues with the call:

blobStoreService.createUploadUrl(...)

I need to track which user Id is associated with the uploaded file. If the user's ID is 1234, I need to store that as metadata on 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 the GAE provided BlobStoreService.createUploadUrl(...) because it supports larger files than this code above can handle. Is it at all possible to specify metadata with the createUploadUrl? Or is it even possible to find out which google storage key/filename is created?


Update I already have the blobKey from the upload callback serlvet. However, I can't find a way to add metadata to the Google Storage file assocated with this blobKey. At least locally, it thinks it 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.

Upvotes: 4

Views: 945

Answers (2)

brariden
brariden

Reputation: 124

I'm thinking this is a bug that file uploads in Google Storage are given BlobKeys which say they are in the BlobStore. Without knowing the generated filename, we can't interact with the uploaded file in GS. For example, we can't add metadata on the file, change ACLs, delete, etc...

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

Upvotes: 2

Paul Collingwood
Paul Collingwood

Reputation: 9116

From the docs:

When the user submits the form, the POST is handled by the Blobstore API, which creates the blob. The API also creates an info record for the blob and stores the record in the datastore, and passes the rewritten request to your application on the given path as a blob key:

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

So once it's uploaded you'll get the blob key which you can then save and add metadata around. I only know about Python but AFAIK you don't get to add that sort of metadata to the blobstore entity, you have to keep track of it yourself.

Upvotes: 0

Related Questions