[英]Wiring jquery file upload to google app engine
I'm trying to add visual drag-and-drop upload capabilities to my GAE-based site using the JQuery File UPload plugin ( see https://github.com/blueimp/jQuery-File-Upload/wiki ). 我正在尝试使用JQuery File UPload插件向基于GAE的站点添加可视化的拖放上传功能(请参阅https://github.com/blueimp/jQuery-File-Upload/wiki )。 While there is a documentation page on the topic ( https://github.com/blueimp/jQuery-File-Upload/wiki/Google-App-Engine ), it falls short of showing the whole process and no matter how much I wrestle this around I cannot get it to work. 虽然有一个关于该主题的文档页面( https://github.com/blueimp/jQuery-File-Upload/wiki/Google-App-Engine ),但是它并没有显示整个过程,无论我如何努力这周围我无法使它工作。
My starting point is a simple single file image upload to the blobstore which redirects to a list of images: 我的出发点是将简单的单个文件图像上传到blobstore,该重定向到图像列表:
class Pic(db.Model):
blob_key = blobstore.BlobReferenceProperty()
url = db.StringProperty(required=True)
creation = db.DateTimeProperty(auto_now_add=True)
class PicUploadForm_Handler(webapp.RequestHandler):
def get(self):
upload_url = blobstore.create_upload_url('/upload_pic/')
self.response.out.write('<html><body>')
self.response.out.write('<form action="%s" method="POST" enctype="multipart/form-data">' % upload_url)
self.response.out.write("""Upload File: <input type="file" name="file"><br> <input type="submit"
name="submit" value="Submit"> </form></body></html>""")
class PicUpload_Handler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_uploads('file') # 'file' is file upload field in the form
blob_info = upload_files[0]
pic = Pic(
blob_key=blob_info.key(),
url=images.get_serving_url(blob_info.key()))
pic.put()
self.redirect('/pics/list/')
class List_Pics(webapp.RequestHandler):
def get(self):
pics = Pic.all()
pics.order("-creation")
results = pics.fetch(5)
html_str = '<html><body>'
for pic in results:
html_str += '<div><a href="%s"><img src="%s"/></a></div>'%(pic.url, pic.url+'=s100')
html_str += '</body></html>'
self.response.out.write(html_str)
Now the Image Plugin has two parts on the client-side which may require customization: This one: 现在,图像插件在客户端具有两个部分,可能需要自定义:这一个:
<script>
$('#fileupload').fileupload({
add: function (e, data) {
var that = this;
$.getJSON('{{upload_url_1}}', function (url) {
data.url = url;
$.blueimpUI.fileupload.prototype
.options.add.call(that, e, data);
});
}
});
</script>
and the upload form: 以及上传表格:
<form action="{{upload_url_2}}" method="POST" enctype="multipart/form-data">
<div class="fileupload-buttonbar">
<label class="fileinput-button">
<span>Add files...</span>
...
After wrangling with this for a day, I cannot figure out what is the role of each one of those urls ( {{upload_url_1}}
and {{upload_url_2}}
in that last snippet). 经过一天的讨论,我无法弄清楚这些网址(最后一个代码段中的{{upload_url_1}}
和{{upload_url_2}}
)的作用是什么。
I have tried hooking one of them to a handler which handles the uploads and returns json with the results, and hook the other one to the handler which allocates the upload url (using create_upload_url()
) but any permutation of this type of wiring failed. 我尝试将其中之一挂接到处理上传并返回json并返回结果的处理程序中,并将另一个挂接到分配上载URL的处理程序中(使用create_upload_url()
),但是这种类型的接线的任何排列都失败了。
Can anyone with experience wiring jquery image upload into GAE python can provide an explanation or a full example? 任何将jquery图像上传到GAE python都有经验的人都可以提供说明或完整示例吗?
upload_url_2
looks like it should correspond to create_upload_url()
. upload_url_2
看起来应该与create_upload_url()
相对应。
upload_url_1
looks like it would be invoked as a callback when a file has been selected, before it gets uploaded. 当文件被选择之前, upload_url_1
看起来将在选择文件后作为回调调用。 If you're not actually trying to accomplish something here, you may be able to omit it. 如果您实际上不是在尝试完成某项任务,则可以忽略它。 Have you tried initializing it without an add
callback, just $('#fileupload').fileupload();
您是否尝试过在没有add
回调的情况下初始化它,只是$('#fileupload').fileupload();
? ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.