mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Updating documentation for usage form-data (#2805)
Closes #2049 Co-authored-by: Xianming Zhong <chinesedfan@qq.com>
This commit is contained in:
@@ -683,6 +683,8 @@ axios(options);
|
|||||||
|
|
||||||
### Node.js
|
### Node.js
|
||||||
|
|
||||||
|
#### Query string
|
||||||
|
|
||||||
In node.js, you can use the [`querystring`](https://nodejs.org/api/querystring.html) module as follows:
|
In node.js, you can use the [`querystring`](https://nodejs.org/api/querystring.html) module as follows:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
@@ -695,6 +697,32 @@ You can also use the [`qs`](https://github.com/ljharb/qs) library.
|
|||||||
###### NOTE
|
###### NOTE
|
||||||
The `qs` library is preferable if you need to stringify nested objects, as the `querystring` method has known issues with that use case (https://github.com/nodejs/node-v0.x-archive/issues/1665).
|
The `qs` library is preferable if you need to stringify nested objects, as the `querystring` method has known issues with that use case (https://github.com/nodejs/node-v0.x-archive/issues/1665).
|
||||||
|
|
||||||
|
#### Form data
|
||||||
|
|
||||||
|
In node.js, you can use the [`form-data`](https://github.com/form-data/form-data) library as follows:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const FormData = require('form-data');
|
||||||
|
|
||||||
|
const form = new FormData();
|
||||||
|
form.append('my_field', 'my value');
|
||||||
|
form.append('my_buffer', new Buffer(10));
|
||||||
|
form.append('my_file', fs.createReadStream('/foo/bar.jpg'));
|
||||||
|
|
||||||
|
axios.post('https://example.com', form, { headers: form.getHeaders() })
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, use an interceptor:
|
||||||
|
|
||||||
|
```js
|
||||||
|
axios.interceptors.request.use(config => {
|
||||||
|
if (config.data instanceof FormData) {
|
||||||
|
Object.assign(config.headers, config.data.getHeaders());
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## Semver
|
## Semver
|
||||||
|
|
||||||
Until axios reaches a `1.0` release, breaking changes will be released with a new minor version. For example `0.5.1`, and `0.5.4` will have the same API, but `0.6.0` will have breaking changes.
|
Until axios reaches a `1.0` release, breaking changes will be released with a new minor version. For example `0.5.1`, and `0.5.4` will have the same API, but `0.6.0` will have breaking changes.
|
||||||
|
|||||||
Reference in New Issue
Block a user