plupload版本:2.1.8(当前最新) 官网:http://www.plupload.com/
服务端使用ASP.NET
操作系统:Windows 8.1
IDE:Visual Studio 2013
浏览器:Chrome 42.0.2311.90
Flash:18.0.0.209完整代码:<html>
<head>
<title>PluploadQueue</title>
<link href="js/jquery.ui.plupload/css/jquery.ui.plupload.css" rel="stylesheet" />
<link href="js/jquery.plupload.queue/css/jquery.plupload.queue.css" rel="stylesheet" /> <script type="text/javascript" src="js/jquery-1.10.1.js"></script>
<script type="text/javascript" src="js/plupload.full.min.js"></script>
<script type="text/javascript" src="js/jquery.plupload.queue/jquery.plupload.queue.min.js"></script>
<script type="text/javascript" src="js/i18n/zh_cn.js"></script> <script type="text/javascript">
// Convert divs to queue widgets when the DOM is ready
$().ready(function () {
$("#uploader").pluploadQueue({
// General settings
runtimes: 'flash,html5,silverlight',
url: 'Upload.ashx',
max_file_size: '10mb',
chunk_size: '1mb',
unique_names: true, // Resize images on clientside if we can
resize: { width: 320, height: 240, quality: 90 }, // Specify what files to browse for
filters: [
{ title: "Image files", extensions: "jpg,gif,png" },
{ title: "Zip files", extensions: "zip" }
], init: {
PostInit: function () {
}, Error: function (up, err) {
console.log(err);
}
}, // Flash settings
flash_swf_url: 'js/Moxie.swf', // Silverlight settings
silverlight_xap_url: 'js/Moxie.xap'
}); // Client side form validation
$('form').submit(function (e) {
var uploader = $('#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)
$('form').submit();
}); uploader.start();
} else
alert('You must at least upload one file.'); e.preventDefault();
}
});
});
</script>
</head><body>
<form>
<div id="uploader">
<p>You browser doesn't have Flash, Silverlight, or HTML5 support.</p>
</div>
</form>
</body>
</html>该代码来自于 http://www.oschina.net/p/plupload,略有修改。现在的问题是:
我想从服务端返回出错信息,有两种方法
Upload.ashx代码如下: public class Upload : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//方法A:抛异常
//throw new Exception("文件类型不符合!"); //方法B:将响应报文的StatusCode改为500,再输出错误信息
context.Response.StatusCode = 500;
context.Response.Write("文件类型不符合!");
} public bool IsReusable
{
get
{
return false;
}
}
}
如果plupload采用html5方式上传:
(上面代码runtimes那一行改为:runtimes: 'html5,flash,silverlight',)无论服务端使用方法A还是方法B,都能够获取到出错信息。
在Error: function (up, err) {这个函数里面,输出结果为:
Object
code: -200
file: n
message: "HTTP 错误。"
response: "文件类型不符合!"(注意这里)
status: 500
__proto__: Object可以看到,response获取到了完整出错信息。如果plupload采用flash方式上传:
(上面代码runtimes那一行改为:runtimes: 'flash,html5,silverlight',)无论服务端使用方法A还是方法B,都不能够获取到出错信息。
在Error: function (up, err) {这个函数里面,输出结果为:
Object
code: -200
file: n
message: "HTTP 错误。"
response: null(注意这里)
responseHeaders: ""
status: 500
__proto__: Object可以看到,response为null。现在的问题是,因为客户端浏览器不一定支持html5,所以只能采用flash(silverlight暂不做考虑,html4已试过不可行)。求flash方式的解决办法,怎样才能获取服务器返回的出错信息。
服务端使用ASP.NET
操作系统:Windows 8.1
IDE:Visual Studio 2013
浏览器:Chrome 42.0.2311.90
Flash:18.0.0.209完整代码:<html>
<head>
<title>PluploadQueue</title>
<link href="js/jquery.ui.plupload/css/jquery.ui.plupload.css" rel="stylesheet" />
<link href="js/jquery.plupload.queue/css/jquery.plupload.queue.css" rel="stylesheet" /> <script type="text/javascript" src="js/jquery-1.10.1.js"></script>
<script type="text/javascript" src="js/plupload.full.min.js"></script>
<script type="text/javascript" src="js/jquery.plupload.queue/jquery.plupload.queue.min.js"></script>
<script type="text/javascript" src="js/i18n/zh_cn.js"></script> <script type="text/javascript">
// Convert divs to queue widgets when the DOM is ready
$().ready(function () {
$("#uploader").pluploadQueue({
// General settings
runtimes: 'flash,html5,silverlight',
url: 'Upload.ashx',
max_file_size: '10mb',
chunk_size: '1mb',
unique_names: true, // Resize images on clientside if we can
resize: { width: 320, height: 240, quality: 90 }, // Specify what files to browse for
filters: [
{ title: "Image files", extensions: "jpg,gif,png" },
{ title: "Zip files", extensions: "zip" }
], init: {
PostInit: function () {
}, Error: function (up, err) {
console.log(err);
}
}, // Flash settings
flash_swf_url: 'js/Moxie.swf', // Silverlight settings
silverlight_xap_url: 'js/Moxie.xap'
}); // Client side form validation
$('form').submit(function (e) {
var uploader = $('#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)
$('form').submit();
}); uploader.start();
} else
alert('You must at least upload one file.'); e.preventDefault();
}
});
});
</script>
</head><body>
<form>
<div id="uploader">
<p>You browser doesn't have Flash, Silverlight, or HTML5 support.</p>
</div>
</form>
</body>
</html>该代码来自于 http://www.oschina.net/p/plupload,略有修改。现在的问题是:
我想从服务端返回出错信息,有两种方法
Upload.ashx代码如下: public class Upload : IHttpHandler
{ public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//方法A:抛异常
//throw new Exception("文件类型不符合!"); //方法B:将响应报文的StatusCode改为500,再输出错误信息
context.Response.StatusCode = 500;
context.Response.Write("文件类型不符合!");
} public bool IsReusable
{
get
{
return false;
}
}
}
如果plupload采用html5方式上传:
(上面代码runtimes那一行改为:runtimes: 'html5,flash,silverlight',)无论服务端使用方法A还是方法B,都能够获取到出错信息。
在Error: function (up, err) {这个函数里面,输出结果为:
Object
code: -200
file: n
message: "HTTP 错误。"
response: "文件类型不符合!"(注意这里)
status: 500
__proto__: Object可以看到,response获取到了完整出错信息。如果plupload采用flash方式上传:
(上面代码runtimes那一行改为:runtimes: 'flash,html5,silverlight',)无论服务端使用方法A还是方法B,都不能够获取到出错信息。
在Error: function (up, err) {这个函数里面,输出结果为:
Object
code: -200
file: n
message: "HTTP 错误。"
response: null(注意这里)
responseHeaders: ""
status: 500
__proto__: Object可以看到,response为null。现在的问题是,因为客户端浏览器不一定支持html5,所以只能采用flash(silverlight暂不做考虑,html4已试过不可行)。求flash方式的解决办法,怎样才能获取服务器返回的出错信息。
解决方案 »
- 两个 div 拖动同步
- 如何用document.writeln函数输出“<!--”和“//-->”。
- 请问如何根据客户端时间判断时区
- 如何让多个不同名称的 checkbox 全选
- 请问关于网页对话框的问题(在线等)
- 如何在超链接上提交表单
- 怎么将一个框架的页面都一次性的屏蔽右键?(很急,谢谢帮忙!)
- if(document.layers){ //这句是什么意思?是检测网页中有没有layer存在吗?
- 动态取得客户端调试信息的工具(ACCESS版,原代码)--立刻可以使用。请近来取,和UP。
- 如何用js实现下列要求,超简单的
- 富文本框的粘贴上传图片功能,怎么抓取到火狐或IE的图片数据?
- 如何改变iframe src 只想页面内容
用输出的内容判断上传状态
但是界面上还是会显示上传成功的,这不符合我的要求啊
但是界面上还是会显示上传成功的,这不符合我的要求啊
1#不是说了,通过判断错误信息来确定是否上传成功。FileUploaded里面判断返回的内容,你服务器没返回500状态当然没执行error
但是界面上还是会显示上传成功的,这不符合我的要求啊
1#不是说了,通过判断错误信息来确定是否上传成功。FileUploaded里面判断返回的内容,你服务器没返回500状态当然没执行error
到触发FileUploaded的时候,界面上已经显示上传成功了,难道要我去改这个组件的源代码?
但是界面上还是会显示上传成功的,这不符合我的要求啊
1#不是说了,通过判断错误信息来确定是否上传成功。FileUploaded里面判断返回的内容,你服务器没返回500状态当然没执行error
到触发FileUploaded的时候,界面上已经显示上传成功了,难道要我去改这个组件的源代码?
那个绿色箭头是flash里面的还是dom对象?如果是dom对象你可以再这个事件里面动态修改那个绿色图标为红色的xx什么的
即客户端flash上传时,会向上传的源站请求一个crossdomain.xml,flash通过crossdomain.xml的内容,判断本次上传是否符合规则。
更多详细内容请参考 OSS Web直传——使用Flash上传-云栖社区-阿里云.html