2016-08-03 63 views
3

私はDropzonejsプラグインを使用しています。ファイルのアップロード時に画像の大きさ(幅と高さ)とファイルサイズを確認したい。私は次元とファイルサイズを調べることができましたが、両方を組み合わせるとうまくいきませんでした。Dropzoneのチェック画像のサイズとファイルのサイズ

var maxImageWidth = 2500, 
    maxImageHeight = 2500; 

Dropzone.options.formUserEdit = { 
    maxFilesize: 2, 
    acceptedFiles: 'image/*', 
    success : function(file, Response){ 
     var obj = JSON.parse(Response); 
     $('#form-user-edit').append('<input type="hidden" name="userprofile" data-ori="'+file.name+'" value="'+obj.filename+'" />'); 

     $('.error-msg').remove(); 
    }, 
    init: function() { 
     this.on("thumbnail", function(file) { 
      if (file.width > maxImageWidth || file.height > maxImageHeight) { 
       file.rejectDimensions(); 
      else { 
       file.acceptDimensions(); 
      } 
     }) 
    }, 
    accept: function(file, done) { 
     file.rejectDimensions = function() { 
      done("Please make sure the image width and height are not larger than 2500px."); 
     }; 
     file.acceptDimensions = done; 
    } 
} 

場合:

  • は大きな寸法の画像をアップロードします。それは、小さな寸法の画像をアップロード

  • 機能を受け入れますが、2メガバイト以上:それはfile.acceptDimensions is not a functionを返しますか、成功に行くことはありません

答えて

0

誰かがまだ答えを必要としている場合。

init: function() { 
    this.on("thumbnail", function(file) { 
     if (file.width > maxImageWidth || file.height > maxImageHeight) { 
      file.rejectDimensions(); 
     else { 
      if(file.size < 1024*1024*2/*2MB*/) 
      { 
       file.acceptDimensions(); 
      } 
     } 
    }) 
},