Skip to content

Commit 9c54e58

Browse files
committed
feat: 下载网络图并保存
1 parent c50504d commit 9c54e58

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/pages/apis/pages/media/image/index.tsx

+21-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: iChengbo
33
* @Date: 2021-07-29 16:44:12
44
* @LastEditors: iChengbo
5-
* @LastEditTime: 2021-07-29 17:57:22
5+
* @LastEditTime: 2021-08-12 18:22:31
66
* @FilePath: /taro-react-native/src/pages/apis/pages/media/image/index.tsx
77
*/
88
import { useState } from 'react';
@@ -104,6 +104,26 @@ const PageView = () => {
104104
})
105105
}}
106106
>Taro.chooseImage</Button>
107+
<Button
108+
type="primary"
109+
className="api-page-btn-success"
110+
onClick={() => {
111+
Taro.downloadFile({
112+
url: 'https://pic1.58cdn.com.cn/nowater/fangfe/n_v2beae27152fcd4d118b60d5284e29d9c9.png',
113+
success: res => {
114+
console.log(res);
115+
if (res.statusCode == 200) {
116+
Taro.showToast({ title: '下载完成(临时文件)', icon: 'none' });
117+
setSource(res.tempFilePath);
118+
}
119+
},
120+
fail: err => {
121+
console.log('下载失败:', err);
122+
Taro.showToast({ title: '下载失败', icon: 'none' });
123+
}
124+
});
125+
}}
126+
>Taro.downloadFile</Button>
107127
</View>
108128
)
109129
}

0 commit comments

Comments
 (0)