当前位置:网站首页>[download file] uniapp develops small programs, downloads files and saves them locally
[download file] uniapp develops small programs, downloads files and saves them locally
2022-07-28 03:18:00 【Ma Xiaotiao's coding advanced road】
One 、 The renderings are as follows :
Realization effect : Click file attachment , Download to local 
Two 、 Specific code :
<view class="contact" @click="downloadFun(item.enclosure)"> Click to download </view>
// Download the attachment
downloadFun(enclosure){
var that = this
console.log(' Print file path :',that.hostUrl + '/uploads'+ enclosure)
uni.downloadFile({
url: that.hostUrl + '/uploads'+ enclosure,// The download address interface returns
success: (data) => {
console.log(' Print data',data)
if (data.statusCode === 200) {
// Save the file locally
uni.saveFile({
tempFilePath: data.tempFilePath, // Temporary path
success: function(res) {
uni.showToast({
icon: 'none',
mask: true,
// title: ' The file has been saved :' + res.savedFilePath, // Save the path
title: ' File downloaded successfully ' ,
duration: 3000,
});
setTimeout(() => {
// Open document view
uni.openDocument({
filePath: res.savedFilePath,
success: function(res) {
// console.log(' Successfully opened the document ');
}
});
}, 3000)
}
});
}
},
fail: (err) => {
console.log(err);
uni.showToast({
icon: 'none',
mask: true,
title: ' File download failed ',
});
},
});
},
ending~
边栏推荐
- 对象数组转成strin再进行,隔开的字符串,包括赛选某个字段的子,或者求和,
- Interview experience: first tier cities move bricks and face software testing posts. 5000 is enough
- Web server
- 决策树与随机森林学习笔记(1)
- 《MySQL数据库进阶实战》读后感(SQL 小虚竹)
- Thread Foundation
- Scheme sharing | experts gather to jointly explore accent AI speech recognition
- QML使用Layout布局时出现大量<Unknown File>: QML QQuickLayoutAttached: Binding loop detected for property循环绑定警告
- OA项目之我的审批(会议查询&会议签字)
- MySQL essay
猜你喜欢

Data Lake (XVII): Flink and iceberg integrate datastream API operations
[email protected]注解使用"/>[email protected]注解使用

stm32F407-------FPU学习

会议OA项目之我的审批&&签字功能

Stm32f407 ------- FPU learning

Promise object

redis网络模型解析

Development and design logic of rtsp/onvif protocol easynvr video platform one click upgrade scheme

【下载文件】uniapp开发小程序,下载文件并保存到本地

4、 Analysis of solid state disk storage technology (paper)
随机推荐
“讳疾忌医”的开源走不远
Brush questions every day to consolidate knowledge
QT official example: Fridge Magnets example
Data Lake: flume, a massive log collection engine
【2022牛客多校2 K Link with Bracket Sequence I】括号线性dp
微服务架构统一安全认证设计与实践
Tungsten Fabric SDN — BGP as a Service
JVM 内存布局详解,图文并茂,写得太好了!
机器人工程是否有红利期
[2022 Niuke multi school 2 K link with bracket sequence I] bracket linear DP
vi命令详解
Vscode debug displays multiple columns of data
STM32之IO模拟串口篇
Intelligent industrial design software company Tianfu C round financing of hundreds of millions of yuan
Data Lake: database data migration tool sqoop
数据湖:各模块组件
满满干货赶紧进来!!!轻松掌握C语言中的函数
上位机与MES对接的几种方式
c#——switch case语句
Redis持久化机制