我想使用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
我不确定如何将disaubleimageresize示例与Coffeescript合并。这就是我所拥有的,它不起作用(我可以运行该应用程序,但似乎没有进行任何调整):
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问题,但两者都没有得到答复:
如何使用jQuery文件上传
调整图像大小尺寸使用jQuery文件上传到Amazon S3
简单的方法是删除添加回调。否则,您负责手动触发调整大小,我尚未找到如何做!