axios-miniprogram/docs/pages/config/download.md

28 lines
533 B
Markdown
Raw Normal View History

2023-04-05 15:24:27 +08:00
# download
## 发送下载请求
2023-04-07 20:38:29 +08:00
可以从服务端下载文件到本地
- 只有 get 请求才生效
2023-04-05 15:24:27 +08:00
2023-04-13 14:16:11 +08:00
```ts
2023-04-05 15:24:27 +08:00
axios
.get(
'/file',
{
// 指定文件下载后存储的路径 (本地路径),选填
2023-04-07 20:38:29 +08:00
filePath: '/file',
2023-04-05 15:24:27 +08:00
},
{
download: true,
},
)
.then((response) => {
2023-04-15 12:20:09 +08:00
// 用户文件路径 (本地路径)。传递 filePath 时会返回,跟传递的 filePath 一致
2023-04-05 15:24:27 +08:00
response.data.filePath;
// 用户文件路径 (本地临时路径)。
response.data.tempFilePath;
});
```