当前位置:网站首页>[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~
边栏推荐
- 【类的本质(Objective-C语言中)】
- MySQL essay
- Blue Bridge Cup: the ninth - "lantern controller"
- c#——switch case语句
- Uniapp——拨打电话、发送短信
- The test post changes jobs repeatedly, jumping and jumping, and then it disappears
- 在线问题反馈模块实战(十六):实现查详情功能
- Data Lake: each module component
- 力扣(LeetCode)208. 实现 Trie (前缀树)(2022.07.27)
- 综合 案例
猜你喜欢

Data Lake: database data migration tool sqoop

Design and practice of unified security authentication for microservice architecture

图像去噪综合比较研究

stm32F407-------DSP学习

Which of the four solutions of distributed session do you think is the best?

Record of a cross domain problem

OA项目之我的审批(会议查询&会议签字)

Interview experience: first tier cities move bricks and face software testing posts. 5000 is enough

Interview experience: first tier cities move bricks and face software testing posts. 5000 is enough

C#实现弹出一个对话框的同时,后面的form不可用
随机推荐
MySQL essay
Engineering Geology Practice - engineering geology problem set
满满干货赶紧进来!!!轻松掌握C语言中的函数
vba批量读取sql的create文来创建表
[acwing 1064 little king] shaped pressure DP
【Codeforces Round #806 (Div. 4)(A~F)】
微服务架构统一安全认证设计与实践
Alibaba cloud international email service package purchase process
图像去噪综合比较研究
综合 案例
Comprehensive comparative study of image denoising
行业洞察 | 语音识别真的超过人耳朵了吗?
Blue Bridge Cup: the ninth - "lantern controller"
牛客-TOP101-BM340
蓝桥杯原题
Redis经典面试题总结
Interview experience: first tier cities move bricks and face software testing posts. 5000 is enough
Stm32f407 ------- DSP learning
Redis持久化机制
Data Lake: each module component