WeChat Mini Program: File Management API Description

高洛峰
Release: 2017-03-03 10:48:36
Original
2839 people have browsed it

wx.saveFile(OBJECT)

Save the file locally.
OBJECT parameter description:
[tr]Parameter type required description[/tr]

##failFunctionNoCallback function for failed interface callcompleteFunctionNoEnd of interface call The callback function (executed successfully or failed)
tempFilePath String is the temporary path of the file that needs to be saved
success Function No Return the save path of the file, res = {savedFilePath: 'Save path of the file'}

Sample code:

wx.startRecord({
    success: function(res) {
        var tempFilePath = res.tempFilePath wx.saveFile({
            tempFilePath: tempFilePath,
            success: function(res) {
                var savedFilePath = res.savedFilePath
            }
        })
    }
}) wx.getSavedFileList(OBJECT)
Copy after login



Get the local saved file list
OBJECT parameter description:[tr]Parameter type required description[/tr]

successFunctionNoThe interface calls the successful callback function. For the return result, see success return parameter descriptionfailFunctionNoCallback function that fails to call the interfacecomplete FunctionNoThe callback function at the end of the interface call (will be executed if the call is successful or failed)

success Return parameter description: [tr]Parameter type description[/tr]

##errMsgfileList
StringInterface call result
Object ArrayFile list
Item description in fileList:

[tr]Key type description[/tr]

filePathcreateTimesize
String Local path of the file
NumberThe timestamp when the file was saved, from 1970/01/01 08:00 :00 The number of seconds to the current time
NumberFile size, unit B
Sample code:

wx.getSavedFileList({
    success: function(res) {
        console.log(res.fileList)
    }
}) wx.getSavedFileInfo(OBJECT)
Copy after login

Copy code

Get file information of local files
OBJECT parameter description:
[tr]Required description of parameter type[/tr]

filePathsuccessfailcomplete
StringYesFile path
FunctionNo The callback function is called successfully by the interface. For the return result, see success return parameter description
FunctionNoInterface call failed The callback function
FunctionNoThe callback function at the end of the interface call (will be executed if the call is successful or failed)
success Return parameter description:

[tr]Parameter type description[/tr]

errMsgsizecreateTime
StringInterface call result
NumberFile size, Unit B
Number The file is saved with a timestamp, from 1970/01/01 08:00:00 to the current time Seconds
Sample code:

wx.getSavedFileInfo({
    filePath: 'wxfile://somefile',
    //仅做示例用,非真正的文件路径 
    success: function(res) {
        console.log(res.size) console.log(res.createTime)
    }
}) wx.removeSavedFile(OBJECT)
Copy after login


##Delete locally stored files

OBJECT parameter description:
[tr]Parameter type required description[/tr]

filePathString is the path of the file that needs to be deletedsuccessFunctionNoCallback function for successful interface callfailFunctionNoCallback function for failed interface callcompleteFunctionNoThe callback function at the end of the interface call (will be executed if the call is successful or failed)

示例代码:

wx.getSavedFileList({
    success: function(res) {
        if (res.fileList.length > 0) {
            wx.removeSavedFile({
                filePath: res.fileList[0].filePath,
                complete: function(res) {
                    console.log(res)
                }
            })
        }
    }
}) wx.openDocument(OBJECT)
Copy after login




新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx
OBJECT参数说明:
[tr]参数说明必填说明[/tr]

filePathString文件路径,可通过 downFile 获得
successFunction接口调用成功的回调函数
failFunction接口调用失败的回调函数
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

wx.downloadFile({
  url: 'http://example.com/somefile.pdf',
  success: function (res) {
    var filePath = res.tempFilePath 
    wx.openDocument({
      filePath: filePath,
      success: function (res) {
        console.log('打开文档成功')
      }
    })
  }
})
Copy after login


更多微信小程序:文件管理 API说明相关文章请关注PHP中文网!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!