httprint/dist/static/js/httprint.js

41 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-08-14 22:19:44 +02:00
function uploadFile() {
let photo = document.getElementById("upload-file").files[0];
let formData = new FormData();
formData.append("file", photo);
var uploadFile = document.getElementById('upload-file');
fetch("/api/upload", {method: "POST", body: formData})
.then(function(response) {
return response.json();
})
.then(function(reply) {
if (reply && !reply.error) {
iziToast.success({
title: "DONE!",
2019-08-15 10:41:24 +02:00
message: reply.message,
2019-08-14 22:19:44 +02:00
position: 'topCenter',
2019-08-15 10:41:24 +02:00
timeout: false,
closeOnEscape: true,
2019-08-14 22:19:44 +02:00
layout: 2
});
} else {
iziToast.error({
title: "ERROR!",
message: reply.message,
position: 'topCenter',
layout: 2
});
}
uploadFile.value = null;
})
.catch(function(err) {
iziToast.error({
title: "ERROR!",
message: "failed to send file",
position: 'topCenter',
layout: 2
});
uploadFile.value = null;
});
}