2014-10-12 3 views
4

이 코드를 사용하여 init에서 데이터베이스의 이미지를 업로드했습니다. 이제이 초기 이미지를 제거하기 위해 새 이미지를 업로드 할 때 원합니다.DropZone init에서 이미지 바꾸기

var o = $("div#uploader").dropzone({ 
      url: "../../Merchant/UploadLogo", 
      paramName: "logo", 
      maxFiles: 1, 

      //enqueueForUpload: false, 
      maxfilesexceeded: function (file) { 
       this.removeAllFiles(); 
       this.addFile(file); 
      }, 

      addRemoveLinks: true, 
      uploadMultiple: false, 
      dictRemoveFile: "حذف", 

      removedfile: function(file) { 
       RemoveFile("Logo"); 
       var _ref; 
       return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0; 
      }, 

      init: function() { 

       var mockFile = { name: "avatar1.jpg", size: 12345, type: 'image/jpeg', url: "../../Merchant/GetLogo" }; 
       this.options.addedfile.call(this, mockFile); 
       this.options.thumbnail.call(this, mockFile, mockFile.url);//uploadsfolder is the folder where you have all those uploaded files 
      } 

     }); 

답변

3

나는 새 이미지가 업로드 될 때마다 Dropzone에서 기존의 이미지를 대체 할 있으리라 믿고있어. 당신은 Dropzone에서 제공하는 this.on('success')this.removeFile 방법을 결합하여 해당 작업을 수행 할 수 있습니다

Dropzone.options.myDropzone = { 
    init: function() { 
     this.on('success', function(file, message) { 
      if (this.files.length > 1) { 
       this.removeFile(this.files[0]); 
      } 
     }); 

     // ... 
    } 
}; 

이 작동하려면, 당신 mockFile은 또한 DROPZONE의 파일 중 하나로 등록해야합니다. 이를 위해, 당신은 바로 그것을 표시 한 후, 당신의 initthis.files 배열로 밀어 수 있습니다

// Create and Display Mock File 
var mockFile = { name: "avatar1.jpg", size: 12345, url: '/image.png' }; 
this.options.addedfile.call(this, mockFile); 
this.options.thumbnail.call(this, mockFile, mockFile.url); 

// Register it 
this.files = [mockFile]; 

출처 : Dropzone#SuccessEvent, Dropzone#Methods 및 경험

+1

신난다,이 'maxFiles'를 통해 업로드를 하나의 파일로 제한하는 것은 정확히해야합니다 (그러나 정확하게하지는 않습니다). – nils