httprint/dist/static/js/httprint.js

43 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-08-14 22:19:44 +02:00
function uploadFile() {
let photo = document.getElementById("upload-file").files[0];
2019-08-15 13:34:44 +02:00
let copies = document.getElementById('copies').value;
2019-08-14 22:19:44 +02:00
let formData = new FormData();
formData.append("file", photo);
2019-08-15 13:34:44 +02:00
formData.append("copies", copies);
var uploadField = document.getElementById('upload-file');
2019-08-14 22:19:44 +02:00
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
});
}
2019-08-15 13:34:44 +02:00
uploadField.value = null;
2019-08-14 22:19:44 +02:00
})
.catch(function(err) {
iziToast.error({
title: "ERROR!",
message: "failed to send file",
position: 'topCenter',
layout: 2
});
2019-08-15 13:34:44 +02:00
uploadField.value = null;
2019-08-14 22:19:44 +02:00
});
}