Google Cloud Storage + App Engine signed url uploa

2019-09-18 12:03发布

问题:

Is there any way to create a handler with signed urls in Google Cloud Storage with Google App Engine (Java)?

I can successfully upload files to buckets with signed URLs in my Android (Java) app but I have no current way of executing additional code server-side upon upload completion.

I have been messing around with the Blobstore API and by creating upload urls that are handled by a servlet in app engine but I can't seem to make it work inside my Cloud Endpoints App Engine project.

Also, signed urls seem favorable to me because I can set expiration times on them.

回答1:

Looks like the only way to do this right now is with object change notifications. Which actually isn't that bad.

I set up a servlet in my Cloud Endpoints App Engine project and in it's doPost() I read in the json body of the request, and parsing it you get all the information you need: https://cloud.google.com/storage/docs/object-change-notification#_Type_AddUpdateDel

Keep in mind this warning from the docs though:

Because of the retry mechanism above, it is possible that notifications are delivered more than once. Ensure that your application is idempotent with respect to processing a unique notification.

So make sure whatever operations you are taking after a notification is sent is idempotent (e.g. doing the operation more than once does not affect the first result of the operation)