当前位置:网站首页>[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~
边栏推荐
- C#设置Textbox控件不可编辑
- Ci/cd from hardware programming to software platform
- Talk about the speech synthesis function of Baidu University of science and technology news Feiyun Zhisheng
- Where do I go to open an account for stock speculation? Is it safe to open an account on my mobile phone
- [nature of class (in Objective-C language)]
- Niuke-top101-bm340
- clientY vs pageY
- C#中关闭窗体的四种方法
- 综合 案例
- [2022 Niuke Game 2 J question link with arithmetic progress] three part set three part / three part extreme value / linear equation fitting least square method
猜你喜欢

基于c8t6芯片开发RC522模块实现呼吸灯

树莓派开发继电器控制灯

R 笔记 MICE

stm32F407-------FPU学习

My approval of OA project (meeting inquiry & meeting signature)

数据湖(十七):Flink与Iceberg整合DataStream API操作

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

Redis内存回收

Distributed transaction Senta (I)

Kubernetes -- Introduction
随机推荐
并发编程面试题总结
ELS displays a random square
vi命令详解
els 显示一个随机方块
方案分享 | 高手云集 共同探索重口音AI语音识别
QT official example: Fridge Magnets example
PCB丝印如何摆?请查收这份手册!
Note that these regions cannot take the NPDP exam in July
Redis通信协议--RESP协议
基于OpenCV的轮廓检测(3)
Redis经典面试题总结
Distributed transaction Senta (I)
[acwing 1064 little king] shaped pressure DP
酒店vr全景展示拍摄提供更多合作和洽谈的机会
Alibaba cloud international email service package purchase process
行业洞察 | 语音识别真的超过人耳朵了吗?
Where do I go to open an account for stock speculation? Is it safe to open an account on my mobile phone
ELS timer
《MySQL数据库进阶实战》读后感(SQL 小虚竹)
53. Maximum Subarray最大子数组和