Skip to main content
 首页 » 编程设计

python之谷歌应用引擎 Python : get image upload size server-side

2025年05月04日17pengyingh

我正在构建一个允许用户上传图片的 Google App Engine 应用程序;我一切正常,但我正在努力寻找一种方法来确保用户不会上传太大的图像(因为我正在调整图像大小,所以这会导致我的 python 脚本崩溃)。 当用户上传大图片时,出现此错误

RequestTooLargeError: The request to API call images.Transform() was too large. 

我知道 GAE 对其图像 API 允许的大小有限制,我只是想找到一种方法来处理这个服务器端;类似

的东西
if (image is too large): 
    inform user 
else: 
    proceed 

我没有运气找到合适的 python 代码来执行此操作;谁能帮帮我?

请您参考如下方法:

from google.appengine.runtime import apiproxy_errors 
 
... 
 
try: 
    #the code you are getting the error at 
except apiproxy_errors.RequestTooLargeError, message: 
    print message # or something else