微信小程序云开发-云存储-上传、下载、打开文件文件(wordexcelpptpdf)一步到位

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

微信⼩程序云开发-云存储-上传、下载、打开⽂件⽂件
(wordexcelpptpdf)⼀步到位
⼀、wxml⽂件
<!-- 上传、下载、打开⽂件⼀步执⾏ -->
<view class="handle">
<button bindtap="handleFile" type="primary">上传下载打开⽂件</button>
<text>实现⽂件的上传、下载、打开⼀步到位</text>
</view>
⼆、wxss⽂件
.handle{
margin: 200rpx 20rpx 0 20rpx;
text-align: center;
}
三、js⽂件
Page({
data:{
fileID :null
},
//功能:上传、下载、打开⽂件⼀⽓呵成
handleFile(){
//选择⽂件
let that = this
wx.chooseMessageFile({
count: 1,
type: 'all',
success (res) {
// tempFilePath可以作为img标签的src属性显⽰图⽚
const tempFilePaths = res.tempFiles
let tempFile = tempFilePaths[0]
that.uploadFile(,tempFile.path)
}
})
},
//上传⽂件
uploadFile(fileName,tempFile){
wx.cloud.uploadFile({
cloudPath:fileName,
filePath:tempFile,
})
.then(res=>{
console.log("⽂件上传成功",res);
//下载⽂件
wx.cloud.downloadFile({
fileID: res.fileID,
success: res => {
console.log("⽂件下载成功",res);
//打开⽂件
const filePath = res.tempFilePath
wx.openDocument({
filePath: filePath,
success: function (res) {
console.log('⽂件打开成功',res)
}
})
}
})
})
.catch(err=>{
console.log("⽂件上传失败",err);
})
}
})
四、实现效果。

相关文档
最新文档