This article mainly shares with you the detailed explanation of the WeChat applet file API, hoping to help everyone.
1. Little knowledge
1.wx.saveFile(OBJECT):Save the file locally.
#
1 2 3 4 5 6 7 8 9 10 11 | wx.chooseImage({
success: function (res) {
var tempFilePaths = res.tempFilePaths
wx.saveFile({
tempFilePath: tempFilePaths[0],
success: function (res) {
var savedFilePath = res.savedFilePath
}
})
}
})
|
Copy after login
2.wx.getSavedFileList(OBJECT):Get the local saved file list
#
1 2 3 4 5 | wx.getSavedFileList({
success: function (res) {
console.log(res.fileList)
}
})
|
Copy after login
3.
wx.getSavedFileInfo(OBJECT):Get the file information of the local file
#
1 2 3 4 5 6 7 | wx.getSavedFileInfo({
filePath: 'wxfile:
success: function (res) {
console.log(res.size)
console.log(res.createTime)
}
})
|
Copy after login
#4.
wx.removeSavedFile(OBJECT):
Delete locally stored files
#
1 2 3 4 5 6 7 8 9 10 11 12 | wx.getSavedFileList({
success: function (res) {
if (res.fileList.length > 0){
wx.removeSavedFile({
filePath: res.fileList[0].filePath,
complete: function (res) {
console.log(res)
}
})
}
}
})
|
Copy after login
5.
wx.openDocument(OBJECT):Open the document in a new page, supported formats: doc,
xls, ppt, pdf, docx, xlsx, pptx
#
1 2 3 4 5 6 7 8 9 10 11 12 | wx.downloadFile({
url: 'http:
success: function (res) {
var filePath = res.tempFilePath
wx.openDocument({
filePath: filePath,
success: function (res) {
console.log('打开文档成功')
}
})
}
})
|
Copy after login
二. Liezi
3.wx.getSavedFileInfo(OBJECT):获取本地文件的文件信息
1 2 3 4 5 | <view class = "container" >
<button type= "primary" bindtap= "upload" >上传文件</button>
<text>文件的路径:{{ path}}px</text>
<text>文件大小:{{ filesize }}</text>
</view>
|
Copy after login
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | var app = getApp()
Page({
data:{
path:'',
filesize :0,
},
upload: function (){
var that=this
wx.chooseImage({
count : 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: function (res) {
var tempFilePaths = res.tempFilePaths;
console.log(tempFilePaths)
wx.getSavedFileInfo({
filePath:res.tempFilePaths[0],
success: function (res) {
that.setData({
filesize :res.size,
})
}
})
that.setData({
path:tempFilePaths
})
}
})
}
})
|
Copy after login
5.wx.openDocument(OBJECT):打开文档
1 2 3 | <view class = "container" >
<button type= "primary" bindtap= "upload" >打开文件</button>
</view>
|
Copy after login
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | var app = getApp()
Page({
data:{
path:'',
},
upload: function (){
var that=this
wx.downloadFile({
url: 'http:
success: function (res) {
var filePath = res.tempFilePath
wx.openDocument({
filePath: filePath,
success: function (res) {
console.log('打开文档成功')
}
})
}
})
}
})
|
Copy after login
这个文件的路径,必须是http或是Https,不能使url: 'D:/WWW/sino-ui/www.941in.com.hk/m.v1/o.pptx',
相关推荐:
jQuery必须掌握的API
PHP如何开发api接口安全验证实例
PHP关于API接口实例分享
The above is the detailed content of Detailed explanation of WeChat applet file API. For more information, please follow other related articles on the PHP Chinese website!