javascript Plupload - 上传功能完成了吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12608744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Plupload - Function on Upload Complete?
提问by Lee
I've been browsing through some 'similar' questions, but none either work or solve the particular issue I'm having.
我一直在浏览一些“类似”的问题,但没有一个可以解决我遇到的特定问题。
I'm using Plupload (http://www.plupload.com) to upload images to Amazon S3. This is working great, however once the uploads are complete, I want to update another div on the page to show thumbnails of the uploaded files. My intention is to use jQuery.load to do this (as I'll need to run a DB query before I can output them). However, for now I'm trying to get the basics working and simply updating the div with text.
我正在使用 Plupload (http://www.plupload.com) 将图像上传到 Amazon S3。这很好用,但是一旦上传完成,我想更新页面上的另一个 div 以显示上传文件的缩略图。我的意图是使用 jQuery.load 来做到这一点(因为我需要在输出它们之前运行一个数据库查询)。但是,现在我正在尝试让基础工作并简单地用文本更新 div。
My current code (below) doesn't return any errors, but it's not updating the div once the file(s) are uploaded. Looking at the various answers/suggestions, there appears to be a variety of ways of achieving what I'm looking for - but I haven't been able to get any working.
我当前的代码(如下)没有返回任何错误,但是一旦文件上传,它就不会更新 div。查看各种答案/建议,似乎有多种方法可以实现我正在寻找的东西 - 但我一直无法找到任何工作。
Here's my code right now...
这是我现在的代码...
<script>
$(document).ready(function(upload) {
$("#uploader").pluploadQueue({
runtimes : 'html5,html4',
url : '/gallery/upload.cfm',
max_file_size : '5000kb',
multiple_queues : true,
unique_names : true,
filters : [
{title : "Image files", extensions : "jpg,gif,png,jpeg"}
]
});
$("#uploader").bind('FileUploaded', function() {
$(".outputimages").html('The output goes here');
});
});
</script>
<div id="uploader">You browser doesn't have HTML 4 support.</div>
<div class="outputimages"></div>
回答by Cybrix
This is my code which is working on my side:
这是我的代码,它在我这边工作:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="plupload/jquery.plupload.queue.js"></script>
<script src="plupload/plupload.full.js"></script>
<script>
$(function() {
$("#uploader").pluploadQueue({
runtimes : 'html5,html4',
max_file_size : '10mb',
url : 'upload.php',
max_file_size : '5000kb',
multiple_queues : true,
unique_names : true,
filters : [
{title : "Image files", extensions : "jpg,gif,png,jpeg"}
]
});
var uploader = $('#uploader').pluploadQueue();
uploader.bind('FileUploaded', function() {
if (uploader.files.length == (uploader.total.uploaded + uploader.total.failed)) {
$(".outputimages").html('The output goes here');
}
});
});
</script>
<div id="uploader">You browser doesn't have HTML 4 support.</div>
<div class="outputimages"></div>
This example, trigger the FileUploaded function after every files in the queue have been uploaded.
本例在队列中的每个文件都上传后触发 FileUploaded 函数。
回答by kinsay
It works better using UploadComplete instead of FileUploaded
使用 UploadComplete 而不是 FileUploaded 效果更好