I am working on a simple app that optimizes images and saves them in cloud storage. I have found an example that takes the file and uses PIL to optimize it. The code looks like this:
def (photo_blob) in the transfer image: blob_key = photo_blob.key () new_blob_key = none img = Image.open (photo_blob.open ()) output = string IO .stringio () img.save (output, img.format, custom = true, quality = 90) opt_img = output.getvalue () output.close () #file file_name = files.blobstore.create (mime_type = photo_blob.content_type) # Open the file and type it with the files. Open (file_name, 'a') f: f.write (opt_img) # Finalize the file. Please do this before trying to read Files.finalize (file_name) # Get the file's Blob Key Return file. BlobStore .get_blob_key (file_name) It works well locally (though I do not know how friendly it is because when I run the uploaded image through something like That it decreases up to 2.4x). However, when I deploy the app and try to upload the images, I often get 500 errors and these messages are found in the log:
F 00: 30: 33.322 156 Since the MB, the soft private reserve limit of 128 MB has exceeded the servicing 7 request total W 00: 30: 33.322 while handling this request, the process handling this request was found to use very much memory and it was Was received. This is likely to use the new process for your application's next request. If you see this message over and over again, you may have a leakage of memory in your application. I have two questions:
- Is it also the best way to optimize and save images in cloud storage?
- How do I prevent these 500 errors from occurring?
Thank you in advance.
The error that you are experiencing due to the memory limit of your instance class is happening.
What I recommend you to do is to edit your .yaml file to configure your module, and specify your instance class to be F2 or greater. If you are not using the module, you need to give GAE your app to "Module: default" to find out that this is your default module. Yumal should also be added at the beginning of the file.
You can see different classes of dictionaries available from this doc, and how to easily configure them
A more basic solution is to limit image size when uploading it But ultimately you will end up with a similar problem.
In relation to past things and one way to customize your images, you may want to take a look at it that provides the ability to manipulate image data using a dedicated image service. . In your case, you may like the "I'm Feeling Lucky" change, you will not need to update your instance class using this API.
No comments:
Post a Comment