Fábio Uechi
Fábio Uechi

Reputation: 837

Enforcing object max size and content/mime type within signed upload URLs

In order to generate expiring upload URLs we are using Cloud Storage signed URLs. Now, we need to restrict the maximum file size (i.e. 32Mb) and also the accepted content-types - only image files will be valid. Are there any built-in mechanism within GCS which allow us to enforce this upload policies?

Upvotes: 2

Views: 1766

Answers (2)

Brian Dorsey
Brian Dorsey

Reputation: 4688

You can restrict the Content-Type, it is an option part of the string when creating the Signed URL. Google Cloud Storage will return when HTTP requests are made for the objects.

It's possible to specify a policy document when preparing a signed POST request, including requirements like expected content-type and content-length-range with a minimum and maximum size.

For cases where the values supported by a policy document are not enough, you can use Object Change Notification to implement custom validation on your uploads, including limiting by size. If an upload didn't meet your rules, you could delete it immediately.

Upvotes: 1

Brandon Gilmore
Brandon Gilmore

Reputation: 21

The POST Object method can be used with an expiring policy document that restricts both the content-length and content-type of the uploaded object.

Upvotes: 2

Related Questions