Use Django views for handling blobstore uploads

前端 未结 4 796
星月不相逢
星月不相逢 2021-02-11 04:16

In stead of using the BlobstoreUploadHandler supplied in AppEngine, I\'d prefer to use a Django view, so I can keep all the urls and view functions together. Howeve

4条回答
  •  情话喂你
    2021-02-11 04:49

    The key info isn't directly in the file, it's in file.blobstore_info.key()

    1. post your form containing your image to a url created using blobstore.create_upload_url():

      from google.appengine.ext import blobstore
      
      upload_url = blobstore.create_upload_url('/add_image/')
      

    the created url will save the image in the blobstore and redirect the request (with modified file object) to /add_image/

    1. define a url pattern and view for /add_image/ and handle the image:

      def add_action_image(request):
          image = request.data.get('image')
          image_key = image.blobstore_info.key()
          ... addl' logic to save a record with the image_key...
      

提交回复
热议问题