Saving Images in App Engine with Django

I am trying to upload and save a modified image in the db.BlobProperty field in Google App Engine using Django.

the relevant part of my view that the request process is as follows:

image = images.resize(request.POST.get('image'), 100, 100)
recipe.large_image = db.Blob(image)
recipe.put()

This seems to be the logical equivalent of the django example in the docs:

from google.appengine.api import images

class Guestbook(webapp.RequestHandler):
  def post(self):
    greeting = Greeting()
    if users.get_current_user():
      greeting.author = users.get_current_user()
    greeting.content = self.request.get("content")
    avatar = images.resize(self.request.get("img"), 32, 32)
    greeting.avatar = db.Blob(avatar)
    greeting.put()
    self.redirect('/')

(source: http://code.google.com/appengine/docs/python/images/usingimages.html#Transform )

But I keep getting the error message: NotImageError / Empty image.

and refers to this line:

image = images.resize(request.POST.get('image'), 100, 100)

. , , , . enctype = "multipart/form-data" . , - , . "request.POST.get('image')", , . ?

.

+5
2

"hcalves" . , Django , App Engine, - 0.96, . , , App Engine Django 1.1 :

from google.appengine.dist import use_library
use_library('django', '1.1')

.

, :

from google.appengine.api import images

image = request.FILES['large_image'].read()
recipe.large_image = db.Blob(images.resize(image, 480))
recipe.put()

, , :

from django.http import HttpResponse, HttpResponseRedirect

def recipe_image(request,key_name):
    recipe = Recipe.get_by_key_name(key_name)

    if recipe.large_image:
        image = recipe.large_image
    else:
        return HttpResponseRedirect("/static/image_not_found.png")

    #build your response
    response = HttpResponse(image)
    # set the content type to png because that what the Google images api 
    # stores modified images as by default
    response['Content-Type'] = 'image/png'
    # set some reasonable cache headers unless you want the image pulled on every request
    response['Cache-Control'] = 'max-age=7200'
    return response
+9

request.FILES ['field_name'].

http://docs.djangoproject.com/en/dev/topics/http/file-uploads/


Google Image API, , - :

from google.appengine.api import images

image = Image(request.FILES['image'].read())
image = image.resize(100, 100)
recipe.large_image = db.Blob(image)
recipe.put()

request.FILES ['image']. read() , Django UploadedFile.

+3

All Articles