将图像文件上传到GAE数据存储区

时间:2013-02-16 18:37:03

标签: google-app-engine upload

我尝试使用CoffeScript中的jQuery将图像文件上传到GAE数据存储区。

我使用的上传jQuery Post功能是:

$.post "/uploadBTS?bts_spriteSheet=#{@bts_spritesheet_url}", (data) =>
      console.log 'succsess'

@bts_spritesheet_url是从html5文件Api:

获得的
handleSpritesheetSelection = (evt) => 
      files = evt.target.files
      f = files[0]
      reader = new FileReader()

      # Closure to capture the file information.
      reader.onload = ((theFile) =>
        return (e) =>   
          @bts_spritesheet_url = e.target
        )(f)
      reader.readAsDataURL(f)
document.getElementById('upload_spritesheet').addEventListener('change', handleSpritesheetSelection, false)

GAE中的handeler对/ uploadBTS的调用是:

class UploadBTS(webapp2.RequestHandler):
  def post(self):

    # get information from form post upload
    bts_spriteSheet = self.request.get('bts_spriteSheet') 

    # create database entry for uploaded image 
    bts_entry = Building_Tile_Sets()
    bts_entry.image = db.Blob(bts_spriteSheet)
    bts_entry.put()

最后,我试图输入信息的数据库是一个定义因此:

# Database containg the bts
class Building_Tile_Sets(db.Model):
  image = db.BlobProperty(default=None)

尝试上传时出现以下错误:

POST http://localhost:8080/uploadBTS?bts_spriteSheet=[object%20FileReader]&bts_jason=[object%20Object]&bts_name=one 500 (OK) 

谁能看到我出错的地方?

0 个答案:

没有答案