Montaner
Montaner

Reputation: 534

How to limit upload size in Google Cloud Storage?

  1. The client asks the backend to upload a file.
  2. The backend returns a session URI to the client (Resumable Uploads with the XML API).
  3. With this session URI the client has permission to upload a file to Google Cloud Storage.

¿How to configure the session URI to allow only a maximum file size?

Upvotes: 4

Views: 4601

Answers (1)

Brandon Yarbrough
Brandon Yarbrough

Reputation: 38369

Unfortunately, starting a resumable upload and passing a session URI to a client does not provide a way to limit file size.

There is, however, a way to do this. Instead of using a resumable PUT upload initiated by the server, have the client initiate its own POST upload using a signed policy document. Policy documents allow the server to provide a list of requirements that an upload must fulfill, one of which is an acceptable range of file sizes. Specifically, you'll need to include this section:

["content-length-range", <min_range>, <max_range>]

You can read about policy documents and how to craft them here: https://cloud.google.com/storage/docs/xml-api/post-object#policydocument

Upvotes: 4

Related Questions