1

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

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

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

@bts_spritesheet_url 是从 html5 File 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 中对 /uploadBTS 的 post 调用的处理程序是:

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) 

谁能看到我哪里出错了?

4

0 回答 0