Reputation: 9415
I'd like to implement client side image resizing using Jquery-File-Upload:
https://github.com/blueimp/jQuery-File-Upload/wiki/Client-side-Image-Resizing
I'd like to implement it in coffeescript, though, to use with some file uploading code I found from this railscast:
http://railscasts.com/episodes/383-uploading-to-amazon-s3
I'm not sure how to incorporate the disableImageResize example with coffeescript. This is what I have, which doesn't work (I can run the app, but it doesn't seem to do any resizing):
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
Can someone tell me what I'm doing incorrectly? I found other StackOverflow questions about the same topic, but both are unanswered:
How to resize images client side using jquery file upload
Resizing image at client-side using JQuery file upload to amazon S3
Upvotes: 2
Views: 3471
Reputation: 720
The simple way is to remove the add callback. Otherwise, you're responsible for triggering the resize manually, which I have yet to find out how to do!
Upvotes: 1