Skip to content

Instantly share code, notes, and snippets.

@sharp
Last active December 9, 2016 14:38
Show Gist options
  • Save sharp/4a21fd705fe60697be6693d560f81c7a to your computer and use it in GitHub Desktop.
Save sharp/4a21fd705fe60697be6693d560f81c7a to your computer and use it in GitHub Desktop.
jquery file upload
$(function () {
$('#file-').fileupload({
dataType: 'json',
type: 'PATCH',
acceptFileTypes: /(\.|\/)(mp4)$/i,
minFileSize: 1000000,
url:"/micro/events/#{@event.id}/episodes/#{@episode.id}/upload",
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 90, 10);
console.log(progress);
$('#progress .bar').css(
'width',
progress + '%'
).text(progress+'%');
},
progressServerRate: 0.5,
progressServerDecayExp: 2,
done: function (e, data) {
console.log(data.result);
$('#progress .bar').css(
'width', '100%'
).text('已完成');
$('#next-step').attr("disabled", false);
},
add: function(e, data) {
var uploadErrors = [];
var acceptFileTypes = /(\.|\/)(mp4)$/i;
if(data.originalFiles[0]['type'].length && !acceptFileTypes.test(data.originalFiles[0]['type'])) {
//alert('请输入MP4格式的视频文件');
//return;
}
if(data.originalFiles[0]['size'].length && data.originalFiles[0]['size'] > 100000) {
alert('上传文件不得超过');
return;
}
if(uploadErrors.length > 0) {
alert(uploadErrors.join("\n"));
} else {
data.submit();
}
},
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment