@epilot/file-client 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,15 +18,26 @@ npm install --save @epilot/file-client
|
|
|
18
18
|
## Usage
|
|
19
19
|
|
|
20
20
|
```typescript
|
|
21
|
+
import fs from 'fs';
|
|
21
22
|
import fileClient from '@epilot/file-client';
|
|
22
23
|
|
|
23
24
|
// get upload params
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const uploadRes = await fileClient.put(
|
|
25
|
+
const uploadFileRes = await fileClient.uploadFile(null, { filename: 'document.pdf', mime_type: 'application/pdf' });
|
|
26
|
+
const uploadParams = uploadFileRes.data;
|
|
27
|
+
|
|
28
|
+
// upload file to S3
|
|
29
|
+
const file = fs.readFileSync('./document.pdf')
|
|
30
|
+
const uploadRes = await fileClient.put(
|
|
31
|
+
uploadParams.upload_url,
|
|
32
|
+
file,
|
|
33
|
+
{ headers: { 'content-type': 'application/json' }}
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
// save file as an entity
|
|
37
|
+
const uploadParams = await fileClient.saveFile(
|
|
38
|
+
null,
|
|
39
|
+
{ s3ref: uploadParams.s3ref, access_control: 'private' },
|
|
40
|
+
);
|
|
30
41
|
```
|
|
31
42
|
|
|
32
43
|
## Documentation
|