使用 webpy 进行 plupload
我想使用 HTML5 运行时使用 plupload 上传文件。
这是我的 html/js 代码:
jQuery(function(){
jQuery("#uploader").pluploadQueue({
// General settings
runtimes : 'html5',
name : 'file',
url : 'http://server.name/addContent',
max_file_size : '${maxSize}$_("GB")',
});
jQuery('#form_upload_file').submit(function(e) {
var uploader = jQuery('#uploader').pluploadQueue();
// Validate number of uploaded files
if (uploader.total.uploaded == 0) {
// Files in queue upload them first
if (uploader.files.length > 0) {
// When all files are uploaded submit form
uploader.bind('UploadProgress', function() {
if (uploader.total.uploaded == uploader.files.length)
jQuery('#form_upload_file').submit();
});
uploader.start();
} else
alert('You must at least upload one file.');
e.preventDefault();
}
});
});
<form id="form_upload_file" action="#" method="POST">
<div id="uploader"></div>
<input type="hidden" name="token" value="token" />
<input type="hidden" name="idUser" value="$idUser" />
</form>
因此,当我单击上传按钮时(未调用 Submit() 方法),它会向我的服务器发出 OPTIONS HTTP 请求 所以我不知道我必须做什么来保存文件?
这是我的 webpy 代码:
def OPTIONS(self):
web.header('Content-type', 'text/plain: charset=utf-8')
web.header('Cache-Control', 'no-store, no-cache, must-revalidate')
web.header('Cache-Control', 'post-check=0, pre-check=0', False)
web.header('Pragma', 'no-cache')
def POST(self):
input = web.input(_unicode=False, file={})#on récupère les input
self.copy(input.file.file)
etc.
知道出了什么问题吗?
I would like to upload a file with plupload with the HTML5 runtime.
This is my html/js code :
jQuery(function(){
jQuery("#uploader").pluploadQueue({
// General settings
runtimes : 'html5',
name : 'file',
url : 'http://server.name/addContent',
max_file_size : '${maxSize}$_("GB")',
});
jQuery('#form_upload_file').submit(function(e) {
var uploader = jQuery('#uploader').pluploadQueue();
// Validate number of uploaded files
if (uploader.total.uploaded == 0) {
// Files in queue upload them first
if (uploader.files.length > 0) {
// When all files are uploaded submit form
uploader.bind('UploadProgress', function() {
if (uploader.total.uploaded == uploader.files.length)
jQuery('#form_upload_file').submit();
});
uploader.start();
} else
alert('You must at least upload one file.');
e.preventDefault();
}
});
});
<form id="form_upload_file" action="#" method="POST">
<div id="uploader"></div>
<input type="hidden" name="token" value="token" />
<input type="hidden" name="idUser" value="$idUser" />
</form>
So, when i click in the button to upload(the submit() method is not called), it does an OPTIONS HTTP request to my server
so i don't know what i must do to save the file?
this is my webpy code :
def OPTIONS(self):
web.header('Content-type', 'text/plain: charset=utf-8')
web.header('Cache-Control', 'no-store, no-cache, must-revalidate')
web.header('Cache-Control', 'post-check=0, pre-check=0', False)
web.header('Pragma', 'no-cache')
def POST(self):
input = web.input(_unicode=False, file={})#on récupère les input
self.copy(input.file.file)
etc.
Any idea what is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有没有看过 webpy 的食谱来解决这个问题?
http://webpy.org/cookbook/fileupload
这个食谱似乎可以完成你想做的事情。
Have you looked webpy's cookbook for this problem?
http://webpy.org/cookbook/fileupload
This recipe seems to accomplish what you want to do.