python - GAE - Upload optimized image to cloud storage -
i'm working on simple app takes images optimizes them , saves them in cloud storage. found example takes file , uses pil optimize it. code looks this:
def inplaceoptimizeimage(photo_blob): blob_key = photo_blob.key() new_blob_key = none img = image.open(photo_blob.open()) output = stringio.stringio() img.save(output,img.format, optimized=true,quality=90) opt_img = output.getvalue() output.close() # create file file_name = files.blobstore.create(mime_type=photo_blob.content_type) # open file , write files.open(file_name, 'a') f: f.write(opt_img) # finalize file. before attempting read it. files.finalize(file_name) # file's blob key return files.blobstore.get_blob_key(file_name)
this works fine locally (although don't know how it's being optimized because when run uploaded image through http://www.jpegmini.com/ gets reduced 2.4x still). when deploy app , try uploading images 500 errors , these messages in logs:
f 00:30:33.322 exceeded soft private memory limit of 128 mb 156 mb after servicing 7 requests total w 00:30:33.322 while handling request, process handled request found using memory , terminated. cause new process used next request application. if see message frequently, may have memory leak in application.
i have 2 questions:
- is best way optimize , save images in cloud storage?
- how prevent these 500 errors occurring?
thanks in advance.
the error you're experiencing happening due memory limits of instance class.
what suggest edit .yaml file in order configure module, , specify instance class f2 or higher. in case not using modules, should add “module: default” @ beginning of app.yaml file let gae know default module.
you can take article docs see different instance classes available, , way configure them.
another more basic workaround limit image size when uploading it, finish having similar issue.
regarding previous matter , way optimize images, may want take @ app engine images api provides ability manipulate image data using dedicated images service. in case, might "i'm feeling lucky" transformation. using api might not need update instance class.
Comments
Post a Comment