【uniapp小程序下载】调用uni.uploadfile方法在调试工具里是没有问题的,但是线上版本和体验版就调用不成功,真机调试也没问题

把你的下载地址前缀添加到合法域名就解决了

在调试工具里成功了是因为勾选了下面这项

下面是我的下载并打开函数

javascript 复制代码
methods: {
	// 下载
	downloadFileFn(data) {
		if (this.detailsObj.currentUserBuy) {
			uni.downloadFile({
				// data是路径
				url: 'https://' + data,
				success(res) {
					//保存到本地
					uni.saveFile({
						tempFilePath: res.tempFilePath, //文件的临时路径
						success: function(res1) {
							const savedFilePath = res1.savedFilePath;
							// 打开文件
							uni.openDocument({
								filePath: savedFilePath,
								success: function(res) {
									uni.hideLoading()
								},
								fail: function(res) {
									console.log(res)
								},
								complete: function(res) {
									setTimeout(uni.hideLoading(), 4000)
								},
							});
						},
						fail: function(err) {
							console.log(err)
						}
					});
				},
				fail(res) {
					console.log(res)
				}
			})
		}
	}
}
相关推荐
局外人LZ1 天前
Uniapp脚手架项目搭建,uniapp+vue3+uView pro+vite+pinia+sass
前端·uni-app·sass
光影少年1 天前
AIGC + Taro / 小程序
小程序·aigc·taro
2501_915918411 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
前端呆头鹅1 天前
Websocket使用方案详解(uniapp版)
websocket·网络协议·uni-app
浮桥1 天前
uniapp+h5 公众号实现分享海报绘制
uni-app·notepad++
2501_916007471 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
天空属于哈夫克31 天前
Go 语言实战:构建一个企微外部群“技术贴收藏夹”小程序后端
小程序·golang·企业微信
wangjun51591 天前
uniapp uni.downloadFile 偶发性下载文件失败 无响应
uni-app
菜鸟una1 天前
【微信小程序+Taro 3+NutUI 3】input (nut-input) 、 textarea (nut-texteare)类型使用避坑
前端·vue.js·微信小程序·小程序·taro
计算机毕设指导61 天前
基于微信小程序的校园二手交易系统【源码文末联系】
java·spring boot·spring·微信小程序·小程序·tomcat·maven