Skip to content

Commit

Permalink
feat: 下载网络图并保存
Browse files Browse the repository at this point in the history
  • Loading branch information
iChengbo committed Aug 12, 2021
1 parent c50504d commit 9c54e58
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/pages/apis/pages/media/image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: iChengbo
* @Date: 2021-07-29 16:44:12
* @LastEditors: iChengbo
* @LastEditTime: 2021-07-29 17:57:22
* @LastEditTime: 2021-08-12 18:22:31
* @FilePath: /taro-react-native/src/pages/apis/pages/media/image/index.tsx
*/
import { useState } from 'react';
Expand Down Expand Up @@ -104,6 +104,26 @@ const PageView = () => {
})
}}
>Taro.chooseImage</Button>
<Button
type="primary"
className="api-page-btn-success"
onClick={() => {
Taro.downloadFile({
url: 'https://pic1.58cdn.com.cn/nowater/fangfe/n_v2beae27152fcd4d118b60d5284e29d9c9.png',
success: res => {
console.log(res);
if (res.statusCode == 200) {
Taro.showToast({ title: '下载完成(临时文件)', icon: 'none' });
setSource(res.tempFilePath);
}
},
fail: err => {
console.log('下载失败:', err);
Taro.showToast({ title: '下载失败', icon: 'none' });
}
});
}}
>Taro.downloadFile</Button>
</View>
)
}
Expand Down

0 comments on commit 9c54e58

Please sign in to comment.