2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-14 15:41:10 +00:00

Test that uploaded image is an image file, return error otherwise

- New javascript function inventreeFileUpload
This commit is contained in:
Oliver Walters
2019-05-06 22:20:06 +10:00
parent c88149b9aa
commit bb702367b6
8 changed files with 86 additions and 53 deletions

View File

@@ -153,7 +153,7 @@
{
accept_text: 'Activate',
accept: function() {
inventreeUpdate(
inventreePut(
"{% url 'api-part-detail' part.id %}",
{
active: true,
@@ -176,7 +176,7 @@
{
accept_text: 'Deactivate',
accept: function() {
inventreeUpdate(
inventreePut(
"{% url 'api-part-detail' part.id %}",
{
active: false,

View File

@@ -108,47 +108,22 @@
var files = transfer.files;
console.log('dropped');
if (files.length > 0) {
var file = files[0];
var formData = new FormData();
var token = getCookie('csrftoken');
formData.append('file', file);
$.ajax({
beforeSend: function(xhr, settings) {
xhr.setRequestHeader('X-CSRFToken', token);
},
url: "{% url 'part-image-upload' part.id %}",
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(data, status, xhr) {
//location.reload();
},
error: function(xhr, status, error) {
console.log('Error uploading thumbnail: ' + status);
console.log(error);
}
});
/*
inventreeUpdate(
inventreeFileUpload(
"{% url 'part-image-upload' part.id %}",
formData,
file,
{},
{
method: 'POST',
dataType: 'json',
success: function(data, status, xhr) {
location.reload();
},
error: function(xhr, status, error) {
showAlertDialog('Error uploading image', renderErrorMessage(xhr));
}
}
);
*/
console.log('submitted');
}
});