UNPKG

1.2 kBHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3
4<head>
5 <meta charset="UTF-8">
6 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 <title>APITable Browser Test</title>
8 <script src="../apitable.browser.js"></script>
9</head>
10
11<body>
12 <pre><code id="V_CODE"></code></pre>
13 <input id="input" name="file" type="file" accept="*">
14
15 <script>
16 function print(r) {
17 document.getElementById('V_CODE').innerText = JSON.stringify(r, null, 2);
18 }
19 APITable.auth({
20 token: "your api token",
21 });
22 const datasheet = APITable.datasheet('datasheet id');
23 datasheet.all().then(r => {
24 print(r);
25 });
26
27 const input = document.getElementById('input');
28 input.onchange = function () {
29 const file = this.files[0];
30 console.log('file', file);
31 // NodeJs can pass in a Buffer or stream to get the file using the input element in the browser.
32 print('uplaoding');
33 datasheet.upload(file).then(response => {
34 /**
35 * response data
36 * success: boolean
37 * code: number
38 * message: string
39 * data: IAttachment
40 */
41 print(response);
42 });
43 };
44 </script>
45</body>
46
47</html>
\No newline at end of file