|
<!DOCTYPE html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="UTF-8"> |
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
|
<title>Upload Image</title> |
|
</head> |
|
<body> |
|
<h1>Upload Image</h1> |
|
<form id="uploadForm"> |
|
<input type="file" id="fileInput" accept="image/*"> |
|
<button type="submit">Upload</button> |
|
</form> |
|
<div id="message"></div> |
|
<div id="imageUrl"></div> |
|
|
|
<script> |
|
document.getElementById('uploadForm').addEventListener('submit', function(event) { |
|
event.preventDefault(); |
|
const fileInput = document.getElementById('fileInput'); |
|
const file = fileInput.files[0]; |
|
if (!file) { |
|
document.getElementById('message').innerText = 'No file selected'; |
|
return; |
|
} |
|
|
|
const formData = new FormData(); |
|
formData.append('file', file); |
|
|
|
fetch('https://api.green-api.com/waInstance1101952913/uploadFile/fb4986a9d9cb40ef9be6c7b08cb9c98b7a3b1dc8c6834b0b92', { |
|
method: 'POST', |
|
body: formData |
|
}) |
|
.then(response => { |
|
if (!response.ok) { |
|
return response.text().then(text => { throw new Error(text) }); |
|
} |
|
return response.json(); |
|
}) |
|
.then(data => { |
|
if (data.urlFile) { |
|
document.getElementById('message').innerText = 'File uploaded successfully'; |
|
document.getElementById('imageUrl').innerHTML = `<a href="${data.urlFile}" target="_blank">Download Image</a>`; |
|
} else { |
|
document.getElementById('message').innerText = 'Failed to upload file'; |
|
} |
|
}) |
|
.catch(error => { |
|
console.error('Error:', error); |
|
document.getElementById('message').innerText = 'Error: ' + error.message; |
|
}); |
|
}); |
|
</script> |
|
</body> |
|
</html> |