Google App Engine Python:获取服务器端的图片上传大小

gog*_*n13 1 python google-app-engine image

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

RequestTooLargeError: The request to API call images.Transform() was too large.
Run Code Online (Sandbox Code Playgroud)

我知道GAE允许它的图像API存在大小限制,我只是想找到一种方法来处理这个服务器端; 一些东西

if (image is too large):
    inform user
else:
    proceed
Run Code Online (Sandbox Code Playgroud)

我没有运气找到正确的python代码来做到这一点; 谁能帮我吗?

bbo*_*boe 5

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
Run Code Online (Sandbox Code Playgroud)