File size: 2,316 Bytes
1d03d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>File Upload to API</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        #response {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #ccc;
            display: none;
        }
        .success { background-color: #dff0d8; color: #3c763d; }
        .error { background-color: #f2dede; color: #a94442; }
    </style>
</head>
<body>
    <h2>Upload File to Convert</h2>
    <form id="uploadForm">
        <input type="file" id="fileInput" name="file" accept=".pptx,.pdf,.docx" required>
        <button type="submit">Upload</button>
    </form>
    <div id="response"></div>

    <script>
        document.getElementById('uploadForm').addEventListener('submit', async (event) => {
            event.preventDefault();

            const fileInput = document.getElementById('fileInput');
            const file = fileInput.files[0];
            if (!file) {
                alert('Please select a file.');
                return;
            }

            const formData = new FormData();
            formData.append('file', file);

            const responseDiv = document.getElementById('response');
            responseDiv.style.display = 'block';
            responseDiv.textContent = 'Uploading...';
            responseDiv.className = '';

            try {
                const response = await fetch('http://localhost:8000/documents', {
                    method: 'POST',
                    body: formData
                });

                const data = await response.json();
                if (response.ok) {
                    responseDiv.className = 'success';
                    responseDiv.textContent = JSON.stringify(data, null, 2);
                } else {
                    responseDiv.className = 'error';
                    responseDiv.textContent = `Error: ${data.detail || JSON.stringify(data)}`;
                }
            } catch (error) {
                responseDiv.className = 'error';
                responseDiv.textContent = `Network Error: ${error.message}`;
            }
        });
    </script>
</body>
</html>