Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7820829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:26:46+00:00 2026-06-02T07:26:46+00:00

I’m working on simple application on GAE using python2.7,the purpose for this application is

  • 0

I’m working on simple application on GAE using python2.7,the purpose for this application is to filter image that are uploaded by the users and store this image in blobstore in GAE,firstly i tried to store the original image(uploaded one)in blobstore then get it by using the url and filter it and lastly store the filtered image on blobstore,the original image is stored correctly but the filtered one isn’t.
This is the code that i tried:

from __future__ import with_statement
from google.appengine.api import files
from PIL import Image
from PIL import ImageFilter
import cgi, cgitb ; cgitb.enable()
from google.appengine.ext import blobstore
from google.appengine.ext import webapp
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp.util import run_wsgi_app
import mimetypes
from google.appengine.ext import blobstore
from mimetypes import guess_type
from google.appengine.api import images


def mime_type(filename):
    return guess_type(filename)[0]
class get(webapp.RequestHandler):
    def post(self):

        form = cgi.FieldStorage() 
        file_upload = form['file']  
        name=file_upload.filename    
        m=mimetypes.guess_type(name)[0]
        u_file = files.blobstore.create(mime_type=m,_blobinfo_uploaded_filename=name)
        data=file_upload.file.read()
        with files.open(u_file, 'a') as f:
                f.write(data)
        files.finalize(u_file)
        blob_key = files.blobstore.get_blob_key(u_file)
        url = images.get_serving_url(blob_key)
        imageFile = str(url)
        img = images.Image(blob_key=blob_key)
        blob_info = blobstore.BlobInfo.get(blob_key)
        im = Image.open(blob_info.open())
        out = im.filter(ImageFilter.EDGE_ENHANCE_MORE)
        u_file = files.blobstore.create(mime_type=m,_blobinfo_uploaded_filename=name)
        data=out
        with files.open(u_file, 'a') as f:
                f.write(data)
        files.finalize(u_file)
        blob_key = files.blobstore.get_blob_key(u_file)
        url = images.get_serving_url(blob_key)
        self.response.out.write("""<html><br><body style="background-color:#CC9999"><b><font size="5" face="Batang" ><center> <li ><img src="%s"</a>
               </center></font><hr></body></html>            
                """ % (str(url)))

def main():
    #application = webapp.WSGIApplication( [('/serve/([^/]+)?', ServeHandler),], debug=True)
    application = webapp.WSGIApplication( [(r'/get.py', get)], debug=True)

    run_wsgi_app(application)


if __name__ == "__main__":
    main()

This is the log file:

2012-04-19 13:36:25.073
Traceback (most recent call last):
  File "/base/data/home/apps/s~filterimages2012/1.358325815417263944/get.py", line 59, in <module>
    main()
  File "/base/data/home/apps/s~filterimages2012/1.358325815417263944/get.py", line 55, in main
    run_wsgi_app(application)
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/webapp/util.py", line 98, in run_wsgi_app
    run_bare_wsgi_app(add_wsgi_middleware(application))
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/webapp/util.py", line 116, in run_bare_wsgi_app
    result = application(env, _start_response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1519, in __call__
    response = self._internal_error(e)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "/base/data/home/apps/s~filterimages2012/1.358325815417263944/get.py", line 43, in post
    f.write(data)
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/files/file.py", line 316, in write
    request.set_data(data)
  File "cpp_message.pyx", line 124, in cpp_message.SetScalarAccessors.Setter (third_party/apphosting/python/protobuf/proto1/cpp_message.cc:2229)
TypeError: <type 'instance'> has type <type 'instance'>, but expected one of: str, unicode

Thanks for help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:26:47+00:00Added an answer on June 2, 2026 at 7:26 am

    The problem is these two lines:

    out = im.filter(ImageFilter.EDGE_ENHANCE_MORE)
    # ...
    data = out
    

    out is a PIL Image object (and thus, data is too), and you’re trying to write that directly to a file. First, you need to serialize the image in a file format of your choice (eg, PNG, JPG). For instance, changing the second line to this will work:

    buf = cStringIO.StringIO()
    out.save(buf, "PNG")
    data = buf.getvalue()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm making a simple page using Google Maps API 3. My first. One marker
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.