-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-upload.html
More file actions
52 lines (44 loc) · 1.68 KB
/
debug-upload.html
File metadata and controls
52 lines (44 loc) · 1.68 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Upload Test</title>
</head>
<body>
<h1>File Upload Test</h1>
<input type="file" id="fileInput" accept="image/*">
<button onclick="uploadFile()">Upload</button>
<div id="result"></div>
<script>
async function uploadFile() {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
if (!file) {
document.getElementById('result').innerHTML = 'No file selected';
return;
}
console.log('File:', file.name, file.type, file.size);
const formData = new FormData();
formData.append('image', file);
formData.append('name', file.name.replace(/\.[^/.]+$/, ''));
console.log('FormData created, uploading...');
try {
const response = await fetch('/api/projects', {
method: 'POST',
body: formData
});
console.log('Response status:', response.status);
const result = await response.text();
console.log('Response text:', result);
document.getElementById('result').innerHTML = `
<h2>Response:</h2>
<p>Status: ${response.status}</p>
<pre>${result}</pre>
`;
} catch (error) {
console.error('Error:', error);
document.getElementById('result').innerHTML = `Error: ${error.message}`;
}
}
</script>
</body>
</html>