当前位置:网站首页>【下载文件】uniapp开发小程序,下载文件并保存到本地
【下载文件】uniapp开发小程序,下载文件并保存到本地
2022-07-28 02:23:00 【马小跳的Coding进阶之路】
一、效果图如下:
实现效果:点击文件附件,下载到本地
二、具体代码:
<view class="contact" @click="downloadFun(item.enclosure)">点击下载</view>
// 下载附件
downloadFun(enclosure){
var that = this
console.log('打印文件路径:',that.hostUrl + '/uploads'+ enclosure)
uni.downloadFile({
url: that.hostUrl + '/uploads'+ enclosure,//下载地址接口返回
success: (data) => {
console.log('打印data',data)
if (data.statusCode === 200) {
//文件保存到本地
uni.saveFile({
tempFilePath: data.tempFilePath, //临时路径
success: function(res) {
uni.showToast({
icon: 'none',
mask: true,
// title: '文件已保存:' + res.savedFilePath, //保存路径
title: '文件下载成功' ,
duration: 3000,
});
setTimeout(() => {
//打开文档查看
uni.openDocument({
filePath: res.savedFilePath,
success: function(res) {
// console.log('打开文档成功');
}
});
}, 3000)
}
});
}
},
fail: (err) => {
console.log(err);
uni.showToast({
icon: 'none',
mask: true,
title: '文件下载失败',
});
},
});
},
ending~
边栏推荐
- Brush questions every day to consolidate knowledge
- Interview experience: first tier cities move bricks and face software testing posts. 5000 is enough
- NPDP candidates! The exam requirements for July 31 are here!
- Ci/cd from hardware programming to software platform
- els 定时器
- Flutter God operation learning (full level introduction)
- Redis群集
- Day 8 of DL
- Comprehensive case
- JS 事件对象 offsetX/Y clientX Y PageX Y
猜你喜欢
![[stream] basic knowledge of stream](/img/33/0bd85f7e029c81d0c20f463ebb972a.png)
[stream] basic knowledge of stream

Kubernetes -- Introduction

嵌入式开发:提示和技巧——用C进行防御性编程的最佳实践

Web服务器

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

Flutter God operation learning (full level introduction)

ECCV 2022 | open source for generative knowledge distillation of classification, detection and segmentation

图像去噪综合比较研究

Qt官方示例:Fridge Magnets Example(冰箱贴)

Actual case of ROS communication
随机推荐
vscode debug显示多列数据
els 显示一个随机方块
行业洞察 | 语音识别真的超过人耳朵了吗?
Day 8 of DL
Pytest the best testing framework
每日刷题巩固知识
tfx airflow 使用体验
Distributed transaction Senta (I)
数据中台建设(三):数据中台架构介绍
Superparameter adjustment and experiment - training depth neural network | pytorch series (26)
Kubernetes -- Introduction
【ACwing 1064 小国王】状压dp
Why is it that when logging in, you clearly use the account information already in the database, but still display "user does not exist"?
Design and practice of unified security authentication for microservice architecture
CNN training cycle reconstruction - hyperparametric test | pytorch series (XXVIII)
ELS keyboard information
写英文IEEE论文的技巧
GAMES101复习:光线追踪(Ray Tracing)
Es6.--promise, task queue and event cycle
els 键盘信息