上传文件
.wxml
<button bindtap="chooseFile">选择文件</button>
.js
Page({
chooseFile(){
var that=this
wx.chooseMessageFile({
count: 1,
type: 'all',
success (res) {
const tempFilePaths = res.tempFiles
console.log(tempFilePaths[0])
that.upload(tempFilePaths[0].path,tempFilePaths[0].name)
}
})
},
upload(tmpFile){
wx.cloud.uploadFile({
cloudPath: '上传的名字',
filePath: tmpFile,
success: res => {
console.log("上传成功",res)
},
fail: err => {
console.log("上传失败",err)
}
})
},
})
下载文件并打开
.wxml
<view>请输入下载链接</view>
<input class="lianjie" bindinput="getContent"></input>
<button bindtap="downLoad">下载</button>
.wxss
.lianjie{
border: 1rpx solid black;
}
.js
Page({
chooseView(){
var that=this
wx.chooseVideo({
sourceType: ['album','camera'],
maxDuration: 60,
camera: 'back',
success(res) {
console.log(res.tempFilePath)
that.uploadView(res.tempFilePath)
}
})
},
uploadView(tmpFile){
wx.cloud.uploadFile({
cloudPath: 'acy.mp4',
filePath: tmpFile,
success: res => {
console.log("上传成功",res)
},
fail: err => {
console.log("上传失败",err)
}
})
},
chooseFile(){
var that=this
wx.chooseMessageFile({
count: 1,
type: 'all',
success (res) {
const tempFilePaths = res.tempFiles
console.log(tempFilePaths[0])
that.upload(tempFilePaths[0].path,tempFilePaths[0].name)
}
})
},
getContent(e){
console.log(e.detail.value)
this.setData({
fileID:e.detail.value
})
},
downLoad(){
var fileID
fileID=this.data.fileID
console.log("下载链接为:",fileID)
wx.cloud.downloadFile({
fileID: fileID,
success: res => {
console.log("下载成功",res)
},
fail: err => {
console.log("下载失败",res)
}
})
},
downLoad(){
var fileID
fileID=this.data.fileID
console.log("下载链接为:",fileID)
wx.cloud.downloadFile({
fileID:fileID,
success:res=>{
console.log("下载成功",res)
const filePath = res.tempFilePath
wx.openDocument({
filePath: filePath,
success:function(res){
console.log('打开文档成功')
}
})
}
})
}
})