文件wx.saveFile(object)保存文件到本地wx.chooseImage({success:function(res){vartempFilePaths=res.tempFilePathswx.saveFile({tempFilePath:tempFilePaths[0],//需要保存的文件的临时路径success:function(res){//返回文件的保存路径varsavedFilePath=res.savedFilePath//文件的保存路径},fail/complete:function(res){//接口调用失败/结束的回调函数}})}})注意:本地文件存储的大小限制为10Mwx.getFileInfo(object)获取本地已保存的文件列表wx.getSavedFileList({success:function(res){res.errMsg//接口调用结果res.fileList//文件列表res.fileList.filePath//文件的本地路径res.fileList.createTime//文件的保存时的时间戳,从1970/01/0108:00:00到当前时间的秒数res.fileList.size//文件大小,单位B},complete:function(res){//接口调用结束的回调函数(调用成功、失败都会执行)}})wx.getSavedFileList(object)获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用wx.getFileInfo接口wx.getSavedFileInfo({filePath:'wxfile://somefile',//文件路径success:function(res){res.errMsg//接口调用结果res.createTime//文件的保存时的时间戳,从1970/01/0108:00:00到当前时间的秒数res.size//文件大小,单位B}complete:function(res){//接口调用结束的回调函数(调用成功、失败都会执行)}})wx.getSavedFileInfo(object)获取本地文件的文件信息。此接口只能用于获取已保存到本地的文件,若需要获取临时文件信息,请使用wx.getFileInfo接口wx.getSavedFileInfo({filePath:'wxfile://somefile',//仅做示例用,非真正的文件路径success:function(res){res.errMsg//接口调用结果res.createTime//文件的保存时的时间戳,从1970/01/0108:00:00到当前时间的秒数res.size//文件大小,单位B}complete:function(res){//接口调用结束的回调函数(调用成功、失败都会执行)}})wx.removeSavedFile(object)删除本地存储的文件wx.getSavedFileList({success:function(res){if(res.fileList.length0){//删除本地存储的文件wx.removeSavedFile({filePath:res.fileList[0].filePath,//需要删除的文件路径success/fail/complete:function(res){//接口调用成功/失败/结束的回调函数}})}}})wx.openDocument(object)新开页面打开文档,支持格式:doc,xls,ppt,pdf,docx,xlsx,pptxwx.downloadFile({url:'http://example.com/somefile.pdf',success:function(res){varfilePath=res.tempFilePathwx.openDocument({filePath:filePath,//(必要)文件路径,可通过downFile获得fileType://文件类型,指定文件类型打开文件,有效值doc,xls,ppt,pdf,docx,xlsx,pptxsuccess/fail/complete:function(res){//接口调用成功/失败/结束的回调函数}})}})

TAG标签: 微信小程序小程序小程序文档

http://www.xiaochengxub.com/read-108020.html