File size: 3,290 Bytes
675e98c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload File</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background-color: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #25D366;
text-align: center;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="file"] {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
background-color: #25D366;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #128C7E;
}
#result {
margin-top: 20px;
padding: 10px;
border-radius: 4px;
}
.success {
background-color: #d4edda;
color: #155724;
}
.error {
background-color: #f8d7da;
color: #721c24;
}
.back-link {
display: block;
margin-top: 20px;
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<h1>Upload File for WhatsApp Bot</h1>
<form id="uploadForm">
<div class="form-group">
<label for="file">Select file to upload:</label>
<input type="file" id="file" name="file" required>
</div>
<button type="submit">Upload</button>
</form>
<div id="result"></div>
<a href="/" class="back-link">← Back to Home</a>
</div>
<script>
document.getElementById('uploadForm').addEventListener('submit', async (e) => {
e.preventDefault();
const fileInput = document.getElementById('file');
const resultDiv = document.getElementById('result');
if (fileInput.files.length === 0) {
resultDiv.className = 'error';
resultDiv.textContent = 'Please select a file to upload';
return;
}
const formData = new FormData();
formData.append('file', fileInput.files[0]);
try {
const response = await fetch('/api/upload', {
method: 'POST',
body: formData
});
const data = await response.json();
if (response.ok) {
resultDiv.className = 'success';
resultDiv.innerHTML = `
<p>File uploaded successfully!</p>
<p><strong>Original Name:</strong> ${data.file.originalName}</p>
<p><strong>File Name:</strong> ${data.file.fileName}</p>
<p><strong>Size:</strong> ${(data.file.size / 1024).toFixed(2)} KB</p>
<p><strong>URL:</strong> <a href="${data.file.url}" target="_blank">${data.file.url}</a></p>
`;
} else {
throw new Error(data.error || 'Failed to upload file');
}
} catch (error) {
resultDiv.className = 'error';
resultDiv.textContent = `Error: ${error.message}`;
}
});
</script>
</body>
</html> |