Spaces:
Running
Running
File size: 1,180 Bytes
907b200 | 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 | <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Upload Test</title>
</head>
<body>
<h1>Upload Test</h1>
<form id="uploadForm" enctype="multipart/form-data">
@csrf
<input type="file" name="file" required>
<button type="submit">Upload</button>
</form>
<div id="result"></div>
<script>
const form = document.getElementById('uploadForm');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const data = new FormData(form);
try {
const response = await fetch('/api/upload-file', {
method: 'POST',
body: data,
});
if (!response.ok) throw new Error('Upload failed');
const json = await response.json();
document.getElementById('result').innerHTML =
`<p>File uploaded! Link:</p>
<a href="${json.url}" target="_blank">${json.url}</a>`;
} catch (err) {
document.getElementById('result').textContent = err;
}
});
</script>
</body>
</html>
|