Storing Images on App Engine using Django

前端 未结 2 789
野趣味
野趣味 2021-02-03 15:08

I\'m trying to upload and save a resized image in a db.BlobProperty field on Google App Engine using Django.

the relevant part of my view that process the request looks

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-03 15:42

    You access uploaded data via request.FILES['field_name'].

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


    Reading more about Google's Image API, seems to me you should be doing something like this:

    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() should work because it's supposed to be a Django's UploadedFile instance.

提交回复
热议问题