2012-11-29 55 views
0

我想通过ajax从表单上传文件到s3。我在客户端使用fineuploader http://fineuploader.com/,在服务器端使用webapp2。它将请求中的参数作为qqfile发送,我可以在请求头中看到图像数据,但我不知道如何在不使用多部分编码的浏览器中将其返回。Webapp2请求应用程序/八位字节流文件上传

这就是我在标准html表单文章中使用multipart进行的操作。

image = self.request.POST["image"] 

这个使用POST我得到的时候给我的映像名称和图像文件

目前我只能够与

image = self.request.get_all('image') 
[u'image_name.png'] 

获取图像文件名后面没有数据关于正在申请的内容标题的警告/八位字节流

<NoVars: Not an HTML form submission (Content-Type: application/octet-stream)> 

我该如何impl在GAE之外的webapp2中使用BlobStoreHandler?

回答

0

我结束了使用fineuploader http://fineuploader.com/它发送一个多编码形式,以我的处理程序的端点。

处理程序内我可以简单地引用POST,然后将FieldStorage对象读入cStringIO对象。

image = self.request.POST["qqfile"] 
imgObj = cStringIO.StringIO(image.file.read()) 

# Connect to S3... 
# create s3 Key 
key = bucket.new_key("%s" % uuid.uuid4()); 

# guess mimetype for headers 
file_mime_type = mimetypes.guess_type(image.filename) 
if file_mime_type[0]: 
    file_headers = {"Content-Type": "%s" % file_mime_type[0]} 
else: 
    file_headers = None 

key.set_contents_from_string(imgObj.getvalue(), headers=file_headers) 

key_str = key.key 

#return JSON response with key and append to s3 url on front end. 

注意:qqfile是fineuploader使用的参数。

我伪装的进展,但没关系我的用例没有需要BlobStoreUploadHandler。

相关问题