-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdocs_sdk_upload-file.html
84 lines (74 loc) · 2.71 KB
/
docs_sdk_upload-file.html
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
72
73
74
75
76
77
78
79
80
81
82
83
84
<!-- Docs - SDK - uploadFile -->
<div class="section">
<h2><a href="/docs/">Docs</a> : <a href="/docs/sdk/">SDK</a> : uploadFile</h2>
<p><span class="font-semibold">uploadFile</span> lets you upload files to a database. The file gets attached to an item, so you must create an item first via <a href="/docs/sdk/insert-item/">insertItem</a> to upload a file. This API will return a promise that gets resolved once the file has been durably stored.</p>
<pre>
<code class="language-javascript">
userbase.uploadFile({
databaseName: 'example-database-name',
itemId: 'example-id',
file: new File(['example'], 'example.txt', { type: 'text/plain' }),
progressHandler: ({ bytesTransferred }) => {
// Display progress using bytesTransferred / file's size
}
}).then(() => {
// file stored durably
}).catch((e) => console.error(e))</code>
</pre>
<h3 id="params">Parameters</h3>
<ul>
<li>
<span class="field">databaseName</span> [string | Len: 1-100] - The database name to use.
</li>
<li>
<span class="field">itemId</span> [string | Len: 1-100] - The item's unique identifier.
</li>
<li>
<span class="field">file</span> [File | Blob] - The file to upload.
</li>
</ul>
<h3 id="advanced-params">Advanced Parameters</h3>
<ul>
<li>
<span class="field">shareToken</span> [string | optional] - The token used to access a shared database.
</li>
<li>
<span class="field">databaseId</span> [string | optional] - The database's unique identifier.
</li>
<li>
<span class="field">progressHandler</span> [function | optional] - A callback that gets invoked for each chunk the file uploads.
<ul>
<li><span class="field">bytesTransferred</span> [number] - Total bytes uploaded to the server.</li>
</ul>
</li>
</ul>
<h3 id="errors">Errors</h3>
<ul>
<li>ParamsMustBeObject</li>
<li>DatabaseNotOpen</li>
<li>DatabaseNameMissing</li>
<li>DatabaseNameMustBeString</li>
<li>DatabaseNameCannotBeBlank</li>
<li>DatabaseNameTooLong</li>
<li>DatabaseNameRestricted</li>
<li>DatabaseIdMustBeString</li>
<li>DatabaseIdCannotBeBlank</li>
<li>DatabaseIdInvalidLength</li>
<li>DatabaseIdNotAllowed</li>
<li>DatabaseIsReadOnly</li>
<li>ItemIdMissing</li>
<li>ItemIdMustBeString</li>
<li>ItemIdCannotBeBlank</li>
<li>ItemIdTooLong</li>
<li>ItemDoesNotExist</li>
<li>FileMustBeFile</li>
<li>FileCannotBeEmpty</li>
<li>FileMissing</li>
<li>FileUploadConflict</li>
<li>TransactionUnauthorized</li>
<li>UserNotSignedIn</li>
<li>TooManyRequests</li>
<li>ServiceUnavailable</li>
</ul>
</div>
<hr>