I am trying to work with dropzone.js but my backend accepts json data with file as base64 string so I implemented ajax into on('sending') function but the problem is dropzone tries to send data normal way and also this so this ajax works but normal post file action fails. How can I disable that standard action and just use mine? Or change default dropzone.js action to send my data json?
$(".dropzone").dropzone({
url: "/file/UploadFile",
autoProcessQueue: false,
init: function () {
var myDropzone = this
$(".submit-file").click(function (e) {
myDropzone.processQueue();
});
this.on("sending", function (file, xhr, formData) {
data = JSON.stringify({ "FileName": file.name.replace(/\.[^/.]+$/, ""), "EncodedFile": file.dataURL.replace(/^data:image\/[a-z]+;base64,/, ""), "FileExtension": file.name.split('.').pop(), "ddID": myDropzone.element.dataset.dropzoneFormId });
$.ajax({
url: "/file/UploadFile",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: 'POST',
dataType: "json",
data: data
}).done(function (data, textStatus, xhr) {
console.log(data);
});
});
}
});