javascript - DropZone Replace image in init - Stack Overflow

I used this code to upload image from database in init. Now I want when upload a new image to remove th

I used this code to upload image from database in init. Now I want when upload a new image to remove this initial image.

 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
            }

        });

I used this code to upload image from database in init. Now I want when upload a new image to remove this initial image.

 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
            }

        });
Share Improve this question edited Jul 1, 2015 at 9:10 Sheharyar 75.9k21 gold badges174 silver badges223 bronze badges asked Oct 12, 2014 at 7:37 mohammed beshermohammed besher 3785 silver badges18 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

I'm assuming you want to replace the old image in the Dropzone whenever a new Image is successfully uploaded. You can do that by bining the this.on('success') and this.removeFile methods provided by Dropzone:

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

        // ...
    }
};

For this to work, your mockFile must also be registered as one of the files of your Dropzone. To do that, you can push it into the this.files array in your init, right after displaying it:

// 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];

Source: Dropzone#SuccessEvent, Dropzone#Methods and Experience

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745403923a4626227.html

相关推荐

  • javascript - DropZone Replace image in init - Stack Overflow

    I used this code to upload image from database in init. Now I want when upload a new image to remove th

    10小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信