Google Gen2 Cloud Function上传10MB+文件触发413请求过大错误排查
调用Google Gen2 Cloud Function上传大文件触发413错误排查
我正尝试通过API Gateway调用Google Gen2 Cloud Function,以POST请求将文件上传至GCS。所有文件大小均小于32MB,但上传10MB及以上文件时,会触发错误:413 Request Entity Too Large: The data value transmitted exceeds the capacity limit.
根据官方文档,Gen2 Cloud Function的最大HTTP请求大小为32MB,但实际仍无法读取上传的大文件。
示例代码
import functions_framework @functions_framework.http def main(request): """HTTP Cloud Function. Args: request (flask.Request): The request object. <https://flask.palletsprojects.com/en/1.1.x/api/#incoming-request-data> Returns: The response text, or any set of values that can be turned into a Response object using `make_response` <https://flask.palletsprojects.com/en/1.1.x/api/#flask.make_response>. """ try: request_json = request.get_json(silent=True) request_args = request.args print(request.files.get('file').content_type) print(request.headers['Fullfilepath']) if request_json and 'name' in request_json: name = request_json['name'] elif request_args and 'name' in request_args: name = request_args['name'] else: name = 'World' return 'Hello {}!'.format(name) except Exception as e: print(e) return "Something went wrong", 500 if __name__ == "__main__": main()
注:文件大小低于10MB时可正常运行
请问为何Gen2 Cloud Function会出现此问题?
补充信息
我使用Postman发起API调用,以下是Postman生成的cURL请求片段:
curl --location --request POST 'https://<gen2-function-url>' \ --header 'Fullfilepath: myFile.xlsx' \ --form 'file=@"/C:/Users/jithin/Downloads/myFile.xlsx"'
CURL OUTPUT (小于10MB - 正常运行):
* Trying 216.249.35.23:443... * TCP_NODELAY set * Connected to <gen2-fn> * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: /etc/ssl/certs * TLSv1.3 (OUT), TLS handshake, Client hello (1): * TLSv1.3 (IN), TLS handshake, Server hello (2): * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8): * TLSv1.3 (IN), TLS handshake, Certificate (11): * TLSv1.3 (IN), TLS handshake, CERT verify (15): * TLSv1.3 (IN), TLS handshake, Finished (20): * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.3 (OUT), TLS handshake, Finished (20): * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 * ALPN, server accepted to use h2 * Server certificate: * subject: CN=*.a.run.app * start date: Sep 26 08:18:32 2022 GMT * expire date: Dec 19 08:18:31 2022 GMT * subjectAltName: host "<gen2-fn>" matched cert's "*.a.run.app" * issuer: C=US; O=Google Trust Services LLC; CN=GTS CA 1C3 * SSL certificate verify ok. * Using HTTP2, server supports multi-use * Connection state changed (HTTP/2 confirmed) * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0 * Using Stream ID: 1 (easy handle 0x6587b7c0) > POST / HTTP/2 > Host: <gen2-fn> > user-agent: curl/7.68.0 > accept: */* > fullfilepath:myFile.xlsx > content-length: 133134 > content-type: multipart/form-data; boundary=------------------------4aa0493a972a819f > * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * old SSL session ID is stale, removing * Connection state changed (MAX_CONCURRENT_STREAMS == 100)! * We are completely uploaded and fine < HTTP/2 200 < content-type: text/html; charset=utf-8 < x-cloud-trace-context: ac66dub6c7d036958f95o05;o=1 < date: Wed, 02 Nov 2022 08:48:59 GMT < server: Google Frontend < content-length: 12 < alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43" < * Connection #0 to host <gen2-fn> left intact Hello World!%
CURL OUTPUT (大于10MB - 运行失败):
* Trying 216.249.35.23:443... * TCP_NODELAY set * Connected to <gen2-fn> * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: /etc/ssl/certs * TLSv1.3 (OUT), TLS handshake, Client hello (1): * TLSv1.3 (IN), TLS handshake, Server hello (2): * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8): * TLSv1.3 (IN), TLS handshake, Certificate (11): * TLSv1.3 (IN), TLS handshake, CERT verify (15): * TLSv1.3 (IN), TLS handshake, Finished (20): * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1): * TLSv1.3 (OUT), TLS handshake, Finished (20): * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 * ALPN, server accepted to use h2 * Server certificate: * subject: CN=*.a.run.app * start date: Oct 17 08:15:34 2022 GMT * expire date: Jan 9 08:15:33 2023 GMT * subjectAltName: host "<gen2-fn>" matched cert's "*.a.run.app" * issuer: C=US; O=Google Trust Services LLC; CN=GTS CA 1C3 * SSL certificate verify ok. * Using HTTP2, server supports multi-use * Connection state changed (HTTP/2 confirmed) * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0 * Using Stream ID: 1 (easy handle 0x5432697c0) > POST / HTTP/2 > Host: <gen2-fn> > user-agent: curl/7.68.0 > accept: */* > fullfilepath:myFile1.xlsx > content-length: 16492439 > content-type: multipart/form-data; boundary=------------------------d75d043c4ffd6fce > * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4): * old SSL session ID is stale, removing * Connection state changed (MAX_CONCURRENT_STREAMS == 100)! * We are completely uploaded and fine < HTTP/2 500 < content-type: text/html; charset=utf-8 < x-cloud-trace-context: 464039806234sdf503247ec892803a20;o=1 < date: Wed, 02 Nov 2022 08:48:21 GMT < server: Google Frontend < content-length: 20 < alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43" < * Connection #0 to host <gen2-fn> left intact Something went wrong%
内容的提问来源于stack exchange,提问作者Jithin Joseph
相关产品推荐
相关产品推荐

