解决 事实证明,在应用程序中加载的js的顺序是错误的:
original:
//= require jquery-fileupload/jquery.fileupload-process
//= require jquery-fileupload/jquery.fileupload-image
//= require jquery-fileupload/jquery.fileupload-validate
correct version:
//= require jquery-fileupload/jquery.fileupload-process
//= require jquery-fileupload/jquery.fileupload-validate
//= require jquery-fileupload/jquery.fileupload-image
我试图使用BlueImp的jquery文件上传程序,我设法让一切正常,但调整大小。
我尝试调整添加回调上的图片大小,然后提交以避免任何服务器端处理。
我知道使用add回调会导致跳过进程函数,但是我在add callback本身中手动调用了它,它应该可以工作,但它没有。
这是我的代码:
$('.jquery-fileupload').fileupload
dataType: "script"
imageMaxWidth: 480
imageMaxHeight: 360
disableImageResize: false
autoUpload: false
process:[
{
action: 'load',
fileTypes: /^image\/(gif|jpeg|png)$/,
maxFileSize: 20000000
},
{
action: 'resize',
maxWidth: 480, // the images are to be loaded into a pdf later so they have to be skept small
maxHeight: 360,
minWidth: 480,
minHeight: 360
},
{
action: 'save'
}
]
progress: (e, data) ->
progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress_'+data.formData.token+' .bar').css('width', progress+'%')
add: (e, data) ->
unique_token = token();
if (data.files && data.files[0])
if(data.files[0].size < 200000000)
if(data.files[0].type.substr(0, data.files[0].type.indexOf('/')) != 'image')
alert("Please upload a file with the correct format")
else
current_data = $(this)
data.process(->
return current_data.fileupload('process', data); //call the process function
).done(->
data.formData = {token: unique_token};
data.context = $('.preview:last');
data.context.find('.abort').click(abortUpload);
xhr = data.submit();
data.context.data('data',{jqXHR: xhr});
)
else
alert("one of your files is over 200MB")
done: (e, data) ->
console.log(data);
任何对此的帮助都会非常感激,因为我已经连续两天在桌子上敲了敲头!
修改 忘了提,这里是我的js文件:
//= require jquery-fileupload/vendor/jquery.ui.widget
//= require jquery-fileupload/vendor/load-image
//= require jquery-fileupload/vendor/canvas-to-blob
//= require jquery-fileupload/jquery.iframe-transport
//= require jquery-fileupload/jquery.fileupload
//= require jquery-fileupload/jquery.fileupload-ui
//= require jquery-fileupload/jquery.fileupload-process
//= require jquery-fileupload/jquery.fileupload-image
//= require jquery-fileupload/jquery.fileupload-validate
//= require jquery-fileupload/vendor/tmpl
//= require jquery-fileupload/locale
答案 0 :(得分:-1)
已解决事实证明在应用程序中加载的js的顺序是错误的:
原:
//= require jquery-fileupload/jquery.fileupload-process
//= require jquery-fileupload/jquery.fileupload-image
//= require jquery-fileupload/jquery.fileupload-validate
正确的版本:
//= require jquery-fileupload/jquery.fileupload-process
//= require jquery-fileupload/jquery.fileupload-validate
//= require jquery-fileupload/jquery.fileupload-image