You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于GCS签名URL上传时设置最大文件大小及Content-Length头部的技术咨询

GCS Signed URL Uploads: File Size Limits & Content-Length Validation

Let's break down your questions clearly, drawing from hands-on experience with GCS signed URLs:

1. Can you set a maximum file size for GCS signed URL uploads?

Absolutely! You can enforce a maximum (and optional minimum) file size by including the x-goog-content-length-range header restriction when generating the signed URL. This header takes two comma-separated values: the minimum allowed byte count and the maximum allowed byte count.

For example, to cap uploads at 10MB (10,485,760 bytes), you'd configure this header to 0,10485760 during the signature creation process. Any upload that exceeds this maximum size will be immediately rejected by GCS with an error response.

2. Does GCS check the Content-Length request header?

Yes, GCS validates the Content-Length header in two key scenarios:

  • When using x-goog-content-length-range: GCS first verifies that the request's Content-Length falls within the defined min/max range. If it doesn't, the upload is rejected right away.
  • Without range restrictions: Even if you don't set a size limit, GCS checks that the actual number of bytes uploaded matches the value specified in Content-Length. If there's a mismatch (e.g., you send fewer bytes than declared), the upload will fail because GCS expects the exact amount of data you indicated.

3. Is it allowed to set a Content-Length larger than the actual file size?

No, this won't work successfully. GCS strictly enforces that the total bytes received match the Content-Length header value.

If you set a Content-Length larger than your actual file size, GCS will wait for the remaining bytes to be sent. Since those bytes never arrive, the request will either time out or return an error (like 411 Length Required or 400 Bad Request). Similarly, setting a Content-Length smaller than the actual file size will cause GCS to reject the upload as soon as it receives more data than declared.


内容的提问来源于stack exchange,提问作者Moritz Schmitz v. Hülst

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 08:48:14