2014-09-05 3 views
-1

양식에서 직접 업로드를 사용하고 있으므로 이미지 크기를 cloudinary으로 업로드하기 전에 유효성을 검사해야합니다. ...업로드하기 전에 이미지 크기를 검색하는 방법

$(".cloudinary-fileupload").fileupload(
# disableImageResize: false, 
imageMinWidth : 460 
imageMinHeight: 230 
acceptFileTypes: /(\.|\/)(gif|jpeg|png|bmp|ico)$/i, 
maxFileSize: 2097152, 
processalways: (e,data) -> 
if (data.files.error) 
alert(data.files[0].error) 

# dropZone: "#direct_upload" 
start: (e) -> 
$(".status").text "Starting upload..." 
return 
progress: (e, data) -> 
$(".status").text "Uploading... " + Math.round((data.loaded * 100.0)/data.total) + "%" 
return 
fail: (e, data) -> 
$(".status").text "Upload failed" 
return 

이 업로드에 사용되는 내 JQuery와 파일 ....

이며,이 cloudinary 할 수있는 이미지를 업로드에 사용되는 뷰 파일입니다

<%= cl_image_upload_tag(:image_id, 
:html => {:id => "resource_image", :class => "hidden"}, 

:tags => "directly_uploaded", 
:crop => :scale, 
:maxFileSize => 2048, 
:resource_type => "image", 
:format => 'jpg', 
:cloudinarydone => true, 
:notification_url => new_image_url 

) %> 

친절하게 말해, 크기가 460 또는 230 이상인 경우 이미지 업로드를 원하는 기능을 수행하는 방법은 사용자가 선택한 그림을 변경하라는 경고를 생성합니다.

답변

0

jQuery 파일 업로드를 사용하여 로컬 파일을 업로드 할 때 크기를 가져올 수 있습니다. 다음과 fileuploadprocessalways에 결합해야합니다

previewThumbnail: false 
previewMaxWidth: 1000 
previewMaxHeight: 1000 
+0

fileuploadprocessalways :

function (e, data) { var width = data.img.width; var height = data.img.height; } 

당신은 같은 일부 jQuery를 파일 업로드 옵션을 켜 모든 추가 JS 라이브러리 아마 jQuery를 파일 업로드에 필요한 및 포함해야 : (e, data) -> width = data.img.width height = data.img.height console.log height // 이건 내 커피 스크립트 파일이고 코드를 사용하고 있지만 콘솔에서는 여전히 인쇄하지 않습니다. 어떤 고도든지 및 더하여 진행중인 기능에서 둘 때 말할 것입니다 정의되지 않은 것을 얻을 수 없다. –

+0

모든 관련 라이브러리가 포함되어 있는지 확인해야합니다. 참조 : https://github.com/cloudinary/cloudinary_js#client-side-image-resizing-before-upload –

관련 문제