Skip to content Skip to sidebar Skip to footer

Change Dropzone Url Dynamically

I'm trying to change the URL in dropzone, and info I've found hasn't seemed to work for me. I have a form that I'm putting a dropzone in using JS. I'd like to change the dropzone U

Solution 1:

You can not change dropzone url using this way. so to do this first create a global variable and on drop down change event(urlSetter) set the value of that variable like below:

var dropzonePostUrl='url.com';
functionurlSetter() {
    var drop = document.getElementById('dropzoneUpload');
    if(type.includes('aud')) {
        dropzonePostUrl = 'url.com';
    } else {
        dropzonePostUrl = 'url2.org';
    }
}

you also need to change your dropzone initialization code as below:

functionaddDropzone() {
    $(document).ready(function () {
        Dropzone.autoDiscover = false;
        $("#dZUpload").dropzone({
            url: "url.com",
            addRemoveLinks: true,
            success: function (file, response) {
                console.log(response);
             },
            init: function () {
               var _this=this;
                this.on("processing", function (file) {
                    _this.options.url = dropzonePostUrl;
                });
            }
        });
    });
}

you can change url in processing event.

Solution 2:

functionaddDropzone() {
  $(document).ready(function () {
    Dropzone.autoDiscover = false;
    $("#dZUpload").dropzone({
      url: "url.com",
      addRemoveLinks: true,
      success: function (file, response) {
      	console.log(response);
      },
      init: function () {
      	this.on("processing", function (file) {
        	this.options.url = dropzonePostUrl;
       	});
      }
    });
  });
}
var dropzonePostUrl='url.com';
functionurlSetter() {
  var drop = document.getElementById('dropzoneUpload');
  if(type.includes('aud')) {
		dropzonePostUrl = 'url.com';
  } else {
		dropzonePostUrl = 'url2.org';
  }
}
<selectid="bioImages"name="bioImages"style="width: 300px;"onchange="urlSetter();"><optionvalue="countryFlag">Country Flag</option><optionvalue="locationImg">Location Image</option><optionvalue="nationalAnthemaud">National Anthem</option><optionvalue="countryNameaud">Country Name</option></select><formid="dropzoneUpload"action=""enctype="multipart/form-data"method="post"><divclass="clearfix"><br><br></div><divclass="half clearfix"><divid="dZUpload"class="dropzone"name="fileUpload"><divclass="dz-default dz-message">
		  	Drop image/audio here or click to upload (system supports 1 file per category).
		  </div></div></div></form>

Post a Comment for "Change Dropzone Url Dynamically"