Skip to content

Commit f06c85f

Browse files
cemremengumcollina
authored andcommitted
Add example snippet for file upload (#36)
* Add example snippet for file upload * Update example to match others
1 parent 2d9fec0 commit f06c85f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,28 @@ try {
4343
}
4444
```
4545

46+
File uploads (multipart/form-data) can be achieved by using [form-data](https://github.com/form-data/form-data) package as shown below:
47+
48+
```js
49+
const FormData = require('form-data')
50+
const fs = require('fs')
51+
52+
try {
53+
const form = new FormData()
54+
form.append('myfile', fs.createReadStream(`./path/to/file`))
55+
56+
const res = await inject(dispatch, {
57+
method: 'post',
58+
url: '/upload',
59+
payload: form,
60+
headers: form.getHeaders()
61+
})
62+
console.log(res.payload)
63+
} catch (err) {
64+
console.log(err)
65+
}
66+
```
67+
4668
## API
4769

4870
#### `inject(dispatchFunc, options, callback)`

0 commit comments

Comments
 (0)