Whenever I try to upload an image successfully, I need to execute the editDataImage()
function in order to fetch the data stored on the server. However, I encounter an error when attempting to display the image data in the dropzone
. Any assistance would be greatly appreciated!
Data Image Retrieval Function
editDataImage(uuid){
var app = this;
app.$http({
url: app.api_url+'/gambarpengambilcontoh/'+uuid,
method: 'GET',
}).then((response)=>{
var app = this;
app.imageList = response.data.data;
app.editGambar();
});
},
Dropzone Function
editGambar(){
var app = this;
Dropzone.autoDiscover = false;
$("#edit_image").dropzone({
url: app.api_url+'/gambarpengambilcontoh/tambah',
paramName: 'gambar_ambil_contoh',
headers: {
'Authorization': 'Bearer '+localStorage.getItem('authToken'),
'Accept': 'Application/json',
},
maxFiles: 10,
maxFilesize: 10,
addRemoveLinks: true,
init: function() {
var myDropzone = this;
if (app.imageList) {
for (var i = 0; i < app.imageList.length; i++) {
var mockFile = {
name: app.imageList[i].gambar_ambil_contoh,
status: Dropzone.ADDED,
url: app.base_url+'/assets/gambarAmbil/'+app.imageList[i].gambar_ambil_contoh,
};
myDropzone.files.push(mockFile);
myDropzone.emit("addedfile", mockFile);
myDropzone.emit("thumbnail", mockFile, app.base_url+'/assets/gambarAmbil/'+app.imageList[i].gambar_ambil_contoh);
myDropzone.emit("processing", mockFile);
myDropzone.emit("success", mockFile);
myDropzone.emit("complete", mockFile);
$('.dz-image').last().find('img').attr({width: '120px', height: '120px'});
}
}
this.on("removedfile", function(file){
$.ajax({
headers: {
'Authorization': 'Bearer '+localStorage.getItem('authToken'),
'Accept': 'Application/json',
},
url: app.api_url+'/gambarpengambilcontoh/delete',
type: 'DELETE',
data: {'gambar_ambil_contoh': file.name}
})
});
this.on('sending', function(file, xhr, formData) {
formData.append('pengambil_contoh_id', app.formData.id);
});
this.on("success", function(file) {
app.editDataImage(app.formData.uuid); // callback to Data Image Retrieval Function
});
}
})
},
Error
Error: Dropzone already attached.
Apologies if my query seems a bit confusing!