forked from albertba/Advertisement_Panel
Rewrote js in jquery and started working on showing images and potentialy addin metadata to images (Spicy lvl, etc)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
let imageInput = $("#imageInput")
|
||||
let imagePreview = $("#preview")
|
||||
|
||||
let uploadForm = $("#imageForm")
|
||||
|
||||
let currentFile = null;
|
||||
|
||||
imageInput.on("change", function() {
|
||||
currentFile = this.files[0];
|
||||
if (currentFile) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
preview.src = e.target.result;
|
||||
preview.style.display = 'block';
|
||||
}
|
||||
reader.readAsDataURL(currentFile);
|
||||
} else {
|
||||
preview.style.display = 'none';
|
||||
}
|
||||
})
|
||||
|
||||
uploadForm.on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (!currentFile) {
|
||||
alert("Please select a file first.");
|
||||
return;
|
||||
}
|
||||
|
||||
let formData = new FormData();
|
||||
formData.append("image", currentFile);
|
||||
|
||||
$.ajax({
|
||||
url: "/upload",
|
||||
type: "POST",
|
||||
data: formData,
|
||||
success: function(response) {
|
||||
alert("Image uploaded successfully!");
|
||||
imageInput.val("");
|
||||
preview.style.display = 'none';
|
||||
currentFile = null;
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
alert("Error uploading image: " + xhr.responseText);
|
||||
}
|
||||
});
|
||||
})
|
||||
Reference in New Issue
Block a user