Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(doc): 中文文档文件上传补充说明 #256

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -818,12 +818,12 @@ request('/api/v1/some/api', { getResponse: true }).then(({ data, response }) =>

### 文件上传

使用 FormData() 构造函数时,浏览器会自动识别并添加请求头 `"Content-Type: multipart/form-data"`, 且参数依旧是表单提交时那种键值对,因此不需要开发者手动设置 **Content-Type**
使用 FormData() 构造函数时,需要制定`requestType: "form"`,然后浏览器会自动识别并添加请求头 `"Content-Type: multipart/form-data"`且参数依旧是表单提交时那种键值对,因此不需要开发者手动设置请求头 **Content-Type**,否则可能接口会报 500 的错误。

```javascript
const formData = new FormData();
formData.append('file', file);
request('/api/v1/some/api', { method: 'post', data: formData });
request('/api/v1/some/api', { method: 'post', requestType: "form", data: formData });
```

如果希望获取自定义头部信息,需要在服务器设置 [Access-Control-Expose-Headers](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers),然后可按照上述方式获取自定义头部信息。
Expand Down