为此,您的客户需要支持 HTML5、File、FileList 和 Blob。你可以看到一个演示它是如何工作的。
更改上传器中的设置非常简单:(文档找到“选项”)
$('#fileupload').fileupload(
'option',
'url',
'/path/to/upload/handler.json'
);
我建议您将图像和视频提交到相同的位置并在服务器端进行检查。这将使您的生活更轻松。
编辑:
这是检查扩展并将图像和视频提交到不同脚本的方法:
function checkFileExtension(file) {
var extension = file.name.split('.').pop().toLowerCase();
var image_extensions = ['gif', 'png', 'jpg', 'jpeg'];
var video_extensions = ['mp4', 'avi', 'wmv'];
// The file extension is not in the array
if ($.inArray(extension, image_extensions) >= 0)
return "image";
else if ($.inArray(extension, video_extensions) >= 0)
return "video";
else
return "notAllowed";
}
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
// This is triggered when you drag'n'drop a file over the uploader
drop: function (e, data) {
$.each(data.files, function (index, file) {
// The file doesn't pass checkFileExtension, return an error
var extension = checkFileExtension(file);
if (extension != "image" && extension != "video") {
// Print an error message in the UI
file.error = "File extension not allowed!";
}
});
},
// This is triggered when you click a button and select files from a list.
change:function (e, data) {
$.each(data.files, function (index, file) {
// The file doesn't pass checkFileExtension, return an error
var extension = checkFileExtension(file);
if (extension != "image" && extension != "video") {
// Print an error message in the UI
file.error = "File extension not allowed!";
}
});
},
// This is triggered on every file in the queue when you click "Upload"
submit: function (e, data) {
// The file is an image - submit those to
if (checkFileExtension(data.files[0]) == "image") {
$('#fileupload').fileupload(
'option',
'url',
'/upload/images'
);
}
// The file is a video.
else if(checkFileExtension(data.files[0]) == "video"){
$('#fileupload').fileupload(
'option',
'url',
'/upload/videos'
);
}
// The file is not a video/image - don't submit the file.
else {
return false;
}
}
});