【发布时间】:2014-01-27 22:12:15
【问题描述】:
我想使用Jquery-File-Upload实现客户端图像大小调整:
https://github.com/blueimp/jQuery-File-Upload/wiki/Client-side-Image-Resizing
不过,我想在 coffeescript 中实现它,以便与我从这个 railscast 中找到的一些文件上传代码一起使用:
http://railscasts.com/episodes/383-uploading-to-amazon-s3
我不确定如何将 disableImageResize 示例与咖啡脚本结合使用。这就是我所拥有的,它不起作用(我可以运行应用程序,但它似乎没有调整大小):
jQuery ->
$('#new_image').fileupload
dataType: "script"
disableImageResize: /Android(?!.*Chrome)|Opera/
.test(window.navigator && navigator.userAgent),
imageMaxWidth: 667,
imageMaxHeight: 667
add: (e, data) ->
types = /(\.|\/)(gif|jpe?g|png)$/i
file = data.files[0]
if types.test(file.type) || types.test(file.name)
$('#images').append('<div class="placeholder"></div>');
$('.placeholder').hide();
data.context = $(tmpl("template-upload", file))
$('#imageUploadProgress').append(data.context)
data.submit()
else
alert("#{file.name} is not a gif, jpeg, or png image file")
progress: (e, data) ->
if data.context
progress = parseInt(data.loaded / data.total * 100, 10)
data.context.find('.bar').css('width', progress + '%')
if progress == 100
$('.placeholder').show();
# scroll to the bottom of the thumbGallery to show recently uploaded image
document.getElementById("images").scrollTop = document.getElementById("images").scrollHeight
谁能告诉我我做错了什么?我发现了关于同一主题的其他 StackOverflow 问题,但都没有答案:
How to resize images client side using jquery file upload
Resizing image at client-side using JQuery file upload to amazon S3
【问题讨论】:
标签: javascript ruby-on-rails coffeescript jquery-file-upload