File size: 2,012 Bytes
1f2d576
89997b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f2d576
 
 
 
 
 
89997b5
1f2d576
89997b5
067e3ba
89997b5
 
 
 
 
1f2d576
89997b5
0de5455
89997b5
1f2d576
b5d4f65
 
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
<!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>