EvalDataSetHugging/templates/addimage.html

49 lines
1.3 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>image Upload</title>
</head>
<body>
<h1>Upload image File</h1>
<form id="image-upload-form" enctype="multipart/form-data">
<input type="file" name="image" id="image-file" accept="image/*" required>
<button type="submit">Upload</button>
</form>
<script>
const form = document.getElementById('image-upload-form');
form.addEventListener('submit', async (event) => {
event.preventDefault();
const fileInput = document.getElementById('image-file');
const imageFile = fileInput.files[0];
if (!imageFile) {
alert('Please select an image file to upload.');
return;
}
const formData = new FormData();
formData.append('image', imageFile);
try {
const response = await fetch('uploadimg', {
method: 'POST',
body: formData
});
if (response.ok) {
const result = await response.json();
alert(`File uploaded successfully: ${result.filename}`);
} else {
const error = await response.json();
alert(`Error uploading file: ${error.message}`);
}
} catch (error) {
alert(`Error uploading file: ${error.message}`);
}
});
</script>
</body>
</html>