Google cloud storage - how to limit size of user u

2019-05-10 20:13发布

问题:

I'm building a service where users can upload images. I want to prevent users from uploading files bigger than 5mb.

Right now I create a 'signed url' for cloud storage user PUT and GET requests. Is there any way I can limit the size of a user upload?

I don't want users to start uploading extremely large files by mistake or with malicious intent.

回答1:

There are three ways to control access to Google Cloud Storage buckets and objects:

Access Control Lists (ACLs), which provide a way to specify read or write access for specified Google accounts and groups.

Signed URLs (Query String Authentication), which provide a way to give time-limited read or write access to anyone in possession of the URL, regardless of whether they have a Google account or not.

Signed Policy Documents, which provide a way to specify what can be uploaded to a bucket. Policy documents allow greater control over size, content type, and other upload characteristics than signed URLs, and can be used by website owners to allow visitors to upload files to Google Cloud Storage.

In this case, you'll need to use the Signed Policy Documents access control method. Take a look at this POST Object article and this case for examples.