tencent cloud

Feedback

Last updated: 2024-03-08 18:12:01

    saveFile

    This method is used via wx.saveFile(Object object)
    Note:
    The storage limit for local files is set at 10 MB.
    Feature Description: Saves files to local storage.
    Note:
    Upon successful invocation, saveFile will relocate the temporary file, rendering the input tempFilePath unusable.
    Parameter and Description:
    Attribute
    Type
    Default value
    Required
    Description
    tempFilePath
    string
    -
    Yes
    Temporary path for the files that need to be stored
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    savedFilePath
    number
    File path after storage
    Sample Code
    wx.chooseImage({
    success(res) {
    const tempFilePaths = res.tempFilePaths
    wx.saveFile({
    tempFilePath: tempFilePaths[0],
    success(res) {
    const savedFilePath = res.savedFilePath
    }
    })
    }
    })

    removeSavedFile

    This method is used via wx.removeSavedFile(Object object).
    Feature Description: Deletes local cache files.
    Parameter and Description:
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    Path for the files that need to be deleted.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    wx.getSavedFileList({
    success(res) {
    if (res.fileList.length > 0) {
    wx.removeSavedFile({
    filePath: res.fileList[0].filePath,
    complete(res) {
    console.log(res)
    }
    })
    }
    }
    })

    openDocument

    This API is used via wx.openDocument(Object object).
    Feature Description: Opens a document on a new page.
    Parameter and Description:
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    File path, which can be obtained through downloadFile.
    fileType
    string
    -
    No
    File type, used to open the file of specified type.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Valid values of object.fileType
    Value
    Description
    doc
    DOC format
    docx
    DOCX format
    xls
    XLS format
    xlsx
    XLSX format
    ppt
    PPT format
    pptx
    PPTX format
    pdf
    PDF format
    Sample Code
    wx.downloadFile({
    // Sample URL, not actually existent
    url: 'https://example.com/somefile.pdf',
    success(res) {
    const filePath = res.tempFilePath
    wx.openDocument({
    filePath,
    success(res) {
    console.log('Document opened successfully')
    }
    })
    }
    })

    getSavedFileList

    This method is used via wx.getSavedFileList(Object object).
    Feature Description: Gets the list of locally cached files saved under this mini program.
    Parameter and Description:
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res
    Attribute
    Type
    Description
    fileList
    Array.\\
    
    File array, with each item being a FileItem.
    Structure of res.fileList
    Attribute
    Type
    Description
    filePath
    string
    Local path
    size
    number
    Local file size, measured in bytes.
    createTime
    number
    Timestamp for file saving, denoting the number of seconds from 08:00:00 on Jan. 01, 1970 to the current time.
    Sample Code
    wx.getSavedFileList({
    success(res) {
    console.log(res.fileList)
    }
    })

    getSavedFilelnfo

    This method is used via wx.getSavedFileInfo(Object object).
    Feature Description: Gets the file information of local files. This interface can only be used to obtain files that have been saved locally. If you need to obtain temporary file information, use the wx.getFileInfo() interface.
    Parameter and Description:
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    File path
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    size
    number
    File size measured in bytes.
    createTime
    number
    Timestamp for file saving, denoting the number of seconds from 08:00:00 on Jan. 01, 1970 to the current time.
    Sample Code
    wx.getSavedFileList({
    success(res) {
    console.log(res.fileList)
    }
    })

    getFileSystemManager

    The API is used via FileSystemManager wx.getFileSystemManager().
    Feature Description: Gets the globally unique file manager, returning the FileSystemManager file manager.

    getFilelnfo

    The API is used via wx.getFileInfo(Object object).
    Feature Description: Gets file information.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    Local File Path
    digestAlgorithm
    string
    'md5'
    No
    Algorithm for calculating file digest.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Valid values of object.digestAlgorithm
    Value
    Description
    md5
    MD5 Algorithm
    sha1
    SHA1 Algorithm
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    size
    number
    File size, measured in bytes.
    digest
    string
    File digest calculated according to the provided digestAlgorithm
    Sample Code
    wx.getFileInfo({
    success(res) {
    console.log(res.size)
    console.log(res.digest)
    }
    })

    FileSystemManager

    .access

    This method is used via FileSystemManager.access(Object object).
    Feature Description: Judges whether a file/directory exists.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    path
    string
    -
    Yes
    The file/directory path to be determined for existence.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail no such file or directory ${path}
    The file/directory does not exist.

    .accessSync

    This method is used via FileSystemManager.accessSync(string path).
    Feature Description: The synced version of FileSystemManager.access.
    Parameter and Description: string path, the file/directory path to be judged for existence.

    .appendFile

    This method is used via FileSystemManager.appendFile(Object object).
    Feature Description: Appends content at the end of the file.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    The path of file to which content is to be appended.
    data
    string/ArrayBuffer
    -
    Yes
    The text or binary data to be appended.
    encoding
    string
    utf-8
    No
    Specifies the character encoding for the file to be written.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Valid values for object.encoding
    Value
    Description
    ascii
    -
    base64
    -
    binary
    -
    hex
    -
    ucs2/ucs-2/utf16le/utf-16le
    Reads in little-endian order.
    utf-8/utf8
    -
    latin1
    -
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail no such file or directory, open ${filePath}
    The specified filePath file does not exist.
    fail illegal operation on a directory, open "${filePath}"
    The specified filePath is an existing directory.
    fail permission denied, open ${dirPath}
    The specified filePath does not have write permissions.
    fail sdcard not mounted
    The specified filePath is an existing directory.

    .appendFileSync

    This method is used via FileSystemManager.appendFileSync(string filePath, string|ArrayBuffer data, string encoding).
    Feature Description: The synced version of FileSystemManager.appendFile.
    Parameter and Description
    string filePath: The path of file to which content is to be appended.
    string|ArrayBuffer data: The text or binary data to be appended.
    string encoding: Specifies the character encoding for writing to the file.
    Valid Values for encoding
    Value
    Description
    ascii
    -
    base64
    -
    binary
    -
    hex
    -
    ucs2/ucs-2/utf16le/utf-16le
    Reads in little-endian order.
    utf-8/utf8
    -
    latin1
    -

    .close

    This method is used via FileSystemManager.close(Object object)
    Feature Description: Closes the file.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    fd
    string
    -
    Yes
    The file descriptor that needs to be closed. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    const fs = wx.getFileSystemManager()
    // Open the file
    fs.open({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    flag: 'a+',
    success(res) {
    // Close the file
    fs.close({
    fd: res.fd
    })
    }
    })

    .closeSync

    This method is used via undefined FileSystemManager.closeSync(Object object).
    Feature Description: Synchronously closes the file.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    fd
    string
    -
    Yes
    The file descriptor that needs to be closed. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface.
    Return Value: undefined.
    Sample Code
    const fs = wx.getFileSystemManager()
    const fd = fs.openSync({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    flag: 'a+'
    })
    
    // Close the file
    fs.closeSync({fd: fd})

    .copyFile

    This method is used via FileSystemManager.copyFile(Object object).
    Feature Description: Copies the file.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    srcPath
    string
    -
    Yes
    Source file path, which can only be a regular file.
    destPath
    string
    -
    Yes
    Destination file path
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail permission denied, copyFile ${srcPath} -> ${destPath}
    The specified destination file path does not have write permissions.
    fail no such file or directory, copyFile ${srcPath} -> ${destPath}
    The source file does not exist, or the parent directory of the destination file path does not exist.

    .copyFileSync

    This method is used via FileSystemManager.copyFileSync(string srcPath, string destPath).
    Feature Description: The synced version of FileSystemManager.copyFile.
    Parameter and description
    string srcPath: Source file path, which can only be a regular file.
    string destPath: Destination file path.

    .getFileInfo

    This method is used via FileSystemManager.getFileInfo(Object object).
    Feature Description: Gets information on local temporary files or local cache files under this mini program.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    The path of the file to be read.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    size
    number
    File size, measured in bytes.
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail file not exist
    The file is not found in the specified filePath.

    .fstat

    This method is used via FileSystemManager.fstat(Object object).
    Feature Description: Gets the status information of the file.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    fd
    string
    -
    Yes
    The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    stats
    Stats
    Get the Stats object of the file, which contains the status information of the file.
    Sample Code
    const fs = wx.getFileSystemManager()
    // Open the file
    fs.open({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    flag: 'a+',
    success(res) {
    // Get the status information of the file.
    fs.fstat({
    fd: res.fd,
    success(res) {
    console.log(res.stats)
    }
    })
    }
    })

    .fstatSync

    This method is used via Stats FileSystemManager.fstatSync(Object object).
    Feature Description: Synchronously gets the status information of the file.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    fd
    string
    -
    Yes
    The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface.
    Return Value:Stats, a Stats object, containing the status information of the file.
    Sample Code
    const fs = wx.getFileSystemManager()
    const fd = fs.openSync({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    flag: 'a+'
    })
    const stats = fs.fstatSync({fd: fd})
    console.log(stats)

    .ftruncate

    This method is used via FileSystemManager.ftruncate(Object object).
    Feature Description: Executes a truncation operation on the file content.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    fd
    string
    -
    Yes
    The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface.
    length
    number
    -
    Yes
    By default, the truncation position is 0. If the specified length value is less than the file length (measured in bytes), only the preceding number of bytes equal to the specified length will be retained in the file, and the remaining content will be deleted. If the specified length exceeds the file length, the file will be expanded, with the extended section being filled with null bytes ('\\0').
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    const fs = wx.getFileSystemManager()
    // Open the file
    fs.open({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    flag: 'a+',
    success(res) {
    //Truncate the file content.
    fs.ftruncate({
    fd: res.fd,
    length: 10, // Truncate the file starting from the 10th byte
    success(res) {
    console.log(res)
    }
    })
    }
    })

    .ftruncateSync

    This method is used via undefined FileSystemManager.ftruncateSync(Object object).
    Feature Description: Executes a truncation operation on the file content.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    fd
    string
    -
    Yes
    The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface.
    length
    number
    -
    Yes
    By default, the truncation position is 0. If the specified length value is less than the file length (measured in bytes), only the preceding number of bytes equal to the specified length will be retained in the file, and the remaining content will be deleted. If the specified length exceeds the file length, the file will be expanded, with the extended section being filled with null bytes ('\\0').
    Return Value: undefined.
    Sample Code
    const fs = wx.getFileSystemManager()
    const fd = fs.openSync({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    flag: 'a+'
    })
    fs.ftruncateSync({
    fd: fd,
    length: 10// Truncate the file starting from the 10th byte
    })

    .getSavedFileList

    This method is used via FileSystemManager.getSavedFileList(Object object).
    Feature Description: Gets the list of locally cached files saved under this mini program.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    fileList
    Array.\\
    Array of files
    Structure of res.fileList
    Attribute
    Type
    Description
    filePath
    string
    Local path
    size
    number
    Local file size, measured in bytes.
    createTime
    number
    Timestamp for file saving, denoting the number of seconds from 08:00:00 on Jan. 01, 1970 to the current time.

    .mkdir

    This method is used via FileSystemManager.mkdir(Object object).
    Feature Description: Creates directory.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    dirPath
    string
    -
    Yes
    Path of the created directory.
    recursive
    boolean
    false
    No
    Whether to create the directory after recursively creating its parent directory. If the corresponding parent directory already exists, this parent directory will not be created. For instance, if dirPath is a/b/c/d and recursive is true, it will create directory a, then create directory b under a, and so forth until directory d under a/b/c is created.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail no such file or directory ${dirPath}
    Parent directory does not exist.
    fail permission denied, open ${dirPath}
    The specified filePath does not have write permissions.
    fail file already exists ${dirPath}
    There exists a file or directory with the same name.

    .mkdirSync

    This method is used via FileSystemManager.mkdirSync(string dirPath, boolean recursive).
    Feature Description: The synced version of FileSystemManager.mkdir.
    Parameter and Description:
    string dirPath: The path of the directory to be created.
    boolean recursive: Whether to create the directory after recursively creating its parent directory. If the corresponding parent directory already exists, this parent directory will not be created. For instance, if dirPath is a/b/c/d and recursive is true, it will create directory a, then create directory b under a, and so forth until directory d under a/b/c is created.

    .open

    This method is used via FileSystemManager.open(Object object).
    Feature Description: Opens a file, returning a file descriptor.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    File path (local path)
    flag
    string
    r
    No
    File system flag, default value: r
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Valid values of flag.
    Valid Values
    Description
    a
    Opens a file for appending. If the file does not exist, it creates the file.
    ax
    Similar to 'a', but will fail if the path exists.
    a+
    Opens a file for reading and appending. If the file does not exist, it creates the file.
    ax+
    Similar + to 'a', but will fail if the path exists.
    as
    Opens a file for appending (in the syncing mode). If the file does not exist, it creates the file.
    as+
    Opens a file for both reading and appending (in the syncing mode). If the file does not exist, it creates the file.
    r
    Opens a file for reading. If the file does not exist, an exception occurs.
    r+
    Opens a file for reading and writing. If the file does not exist, an exception occurs.
    w
    Opens a file for writing. If the file does not exist, it creates the file; if the file exists, it truncates the file.
    wx
    Similar to 'w', but will fail if the path exists.
    w+
    Opens a file for reading and writing. If the file does not exist, it creates the file; if the file exists, it truncates the file.
    wx+
    Similar to 'w+', but will fail if the path exists.
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    fd
    string
    File descriptor
    Sample Code
    const fs = wx.getFileSystemManager()
    fs.open({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    flag: 'a+',
    success(res) {
    console.log(res.fd)
    }
    })

    .openSync

    This method is used via string FileSystemManager.openSync(Object object).
    Feature Description: Synchronously opens a file, returning a file descriptor.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    File path (local path)
    flag
    string
    r
    No
    File system flag, default value: r
    Valid values of flag.
    Valid Values
    Description
    a
    Opens a file for appending. If the file does not exist, it creates the file.
    ax
    Similar to 'a', but will fail if the path exists.
    a+
    Opens a file for reading and appending. If the file does not exist, it creates the file.
    ax+
    Similar + to 'a', but will fail if the path exists.
    as
    Opens a file for appending (in the syncing mode). If the file does not exist, it creates the file.
    as+
    Opens a file for both reading and appending (in the syncing mode). If the file does not exist, it creates the file.
    r
    Opens a file for reading. If the file does not exist, an exception occurs.
    r+
    Opens a file for reading and writing. If the file does not exist, an exception occurs.
    w
    Opens a file for writing. If the file does not exist, it creates the file; if the file exists, it truncates the file.
    wx
    Similar to 'w', but will fail if the path exists.
    w+
    Opens a file for reading and writing. If the file does not exist, it creates the file; if the file exists, it truncates the file.
    wx+
    Similar to 'w+', but will fail if the path exists.
    Return Value: String, the file descriptor.
    Sample Code
    const fs = wx.getFileSystemManager() const fd = fs.openSync({ filePath: ${wx.env.USER_DATA_PATH}/hello.txt, flag: 'a+' }) console.log(fd)

    .read

    This method is used via FileSystemManager.read(Object object).
    Feature Description: Reads a file.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    fd
    string
    -
    Yes
    The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface.
    arrayBuffer
    ArrayBuffer
    -
    Yes
    The buffer for data writing must be an instance of ArrayBuffer.
    offset
    number
    0
    No
    The write offset in the buffer, with the default value being 0.
    length
    number
    0
    No
    The number of bytes to read from the file, with the default value being 0.
    position
    number
    -
    No
    The starting position for file reading. If not provided or null, the file will be read from the current file pointer position. If the position is a positive integer, the file pointer position will remain unchanged and the file will be read from the position.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    bytesRead
    number
    The actual number of bytes read.
    arrayBuffer
    ArrayBuffer
    The object of the buffer being written to, that is, the arrayBuffer parameter of the interface.
    Sample Code
    const fs = wx.getFileSystemManager()
    const ab = new ArrayBuffer(1024)
    // Open the file
    fs.open({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    flag: 'a+',
    success(res) {
    //Read the file into the ArrayBuffer
    fs.read({
    fd: res.fd,
    arrayBuffer: ab,
    length: 10,
    success(res) {
    console.log(res)
    }
    })
    }
    })

    .readSync

    This method is used via ReadResult FileSystemManager.readSync(Object object).
    Feature Description: Reads a file.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    fd
    string
    -
    Yes
    The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface.
    arrayBuffer
    ArrayBuffer
    -
    Yes
    The buffer for data writing must be an instance of ArrayBuffer.
    offset
    number
    0
    No
    The write offset in the buffer, with the default value being 0.
    length
    number
    0
    No
    The number of bytes to read from the file, with the default value being 0.
    position
    number
    -
    No
    The starting position for file reading. If not provided or null, the file will be read from the current file pointer position. If the position is a positive integer, the file pointer position will remain unchanged and the file will be read from the position.
    Return Value:ReadResult, the result of the file read.
    Sample Code
    const fs = wx.getFileSystemManager()
    const ab = new ArrayBuffer(1024)
    const fd = fs.openSync({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    flag: 'a+'
    })
    const res = fs.readSync({
    fd: fd,
    arrayBuffer: ab,
    length: 10
    })
    console.log(res)

    .readCompressedFile

    This method is used via FileSystemManager.readCompressedFile(Object object).
    Feature Description: Reads the content of a local file of a specified compression type.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    The path of the file to be read (local user file or code package file).
    compressionAlgorithm
    string
    -
    Yes
    File compression type, currently only supporting br: brotli compressed files.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    data
    ArrayBuffer
    Version content
    Sample Code
    const fs = wx.getFileSystemManager()
    
    //Asynchronous Interface
    fs.readCompressedFile({
    filePath: '${wx.env.USER_DATA_PATH}/hello.br',
    compressionAlgorithm: 'br',
    success(res) {
    console.log(res.data)
    },
    fail(res) {
    console.log('readCompressedFile fail', res)
    }
    })
    
    //Synchronous Interface
    const data = fs.readCompressedFileSync({
    filePath: '${wx.env.USER_DATA_PATH}/hello.br',
    compressionAlgorithm: 'br',
    })
    console.log(data)

    .readCompressedFileSync

    This method is used via ArrayBuffer FileSystemManager.readCompressedFileSync(Object object).
    Feature Description: Synchronously reads the content of a local file of a specified compression type.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    The path of the file to be read (local user file or code package file).
    compressionAlgorithm
    string
    -
    Yes
    File compression type, currently only supporting br: brotli compressed files.
    Return Value: ArrayBuffer, the file reading result.
    Sample Code
    const fs = wx.getFileSystemManager()
    
    //Asynchronous Interface
    fs.readCompressedFile({
    filePath: '${wx.env.USER_DATA_PATH}/hello.br',
    compressionAlgorithm: 'br',
    success(res) {
    console.log(res.data)
    },
    fail(res) {
    console.log('readCompressedFile fail', res)
    }
    })
    
    //Synchronous Interface
    try {
    const data = fs.readCompressedFileSync({
    filePath: '${wx.env.USER_DATA_PATH}/hello.br',
    compressionAlgorithm: 'br',
    })
    console.log(data)
    } catch (err) {
    console.log(err)
    }

    .readdir

    This method is used via FileSystemManager.readdir(Object object).
    Feature Description: Reads the list of files in the directory.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    dirPath
    string
    -
    Yes
    The directory path to be read.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    files
    Array.\\
    An array of file names in the specified directory.
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail no such file or directory ${dirPath}
    The directory does not exist.
    fail not a directory ${dirPath}
    dirPath is not a directory.
    fail permission denied, open ${dirPath}
    The specified filePath does not have read permissions.

    .readdirSync

    This method is used via Array.<string> FileSystemManager.readdirSync(string dirPath).
    Feature Description: The synced version of FileSystemManager.readdir.
    Parameters and Description: string dirPath, the directory path to be read.
    Return Value: Array.<string> files, an array of file names in the specified directory.

    .readFile

    This method is used via FileSystemManager.readFile(Object object).
    Feature Description: Reads the content of a local file.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    The path of the file to be read.
    encoding
    string
    -
    No
    Specifies the character encoding for reading the file. If encoding is not provided, the file's binary content is read in ArrayBuffer format.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Valid values for object.encoding
    Value
    Description
    ascii
    -
    base64
    -
    binary
    -
    hex
    -
    ucs2/ucs-2/utf16le/utf-16le
    Reads in little-endian order.
    utf-8/utf8
    -
    latin1
    -
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    data
    string/ArrayBuffer
    Version content
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail no such file or directory, open ${filePath}
    The directory of the specified filePath does not exist.
    fail permission denied, open ${dirPath}
    The specified filePath does not have read permissions.

    .readFileSync

    This method is used via string|ArrayBuffer FileSystemManager.readFileSync(string filePath, string encoding).
    Feature Description: The synced version of FileSystemManager.readFile.
    Parameter and Description:
    string filePath: The path of the file to be read.
    string encoding: Specifies the character encoding for reading the file. If encoding is not provided, the file's binary content is read in ArrayBuffer format.
    Valid Values for encoding
    Value
    Description
    ascii
    -
    base64
    -
    binary
    -
    hex
    -
    ucs2/ucs-2/utf16le/utf-16le
    Reads in little-endian order.
    utf-8/utf8
    -
    latin1
    -
    Return Value: string|ArrayBuffer data, the file content.

    .readZipEntry

    This method is used via FileSystemManager.readZipEntry(Object object).
    Feature Description: Reads a file within a compressed package.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    The path of the compressed package to be read (local path).
    encoding
    string
    -
    No
    Uniformly specifies the character encoding for reading the file, effective only when the entries value is "all". If the entries value is "all" and encoding is not provided, the file's binary content is read in ArrayBuffer format.
    entries
    Array.<Object>/'all'
    -
    Yes
    The list of files within the compressed package to be read (when "all" is passed in, it signifies reading all files within the compressed package).
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Valid values for encoding
    Value
    Description
    ascii
    -
    base64
    -
    binary
    -
    hex
    -
    ucs2/ucs-2/utf16le/utf-16le
    Reads in little-endian order.
    utf-8/utf8
    -
    latin1
    -
    
    Structure Attributes of Entries
    Structure attributes
    Type
    Default value
    Required
    Description
    path
    string
    -
    Yes
    Path of the file within the compressed package.
    encoding
    string
    -
    No
    Specifies the character encoding for reading the file. If encoding is not provided, the file's binary content is read in ArrayBuffer format.
    position
    number
    -
    No
    Start reading from a specified position in the file; if not specified, reading begins from the start of the file. The reading range should be a left-closed and right-open interval [position, position+length). The valid range is [0, fileLength - 1] in bytes.
    length
    number
    -
    No
    Specify the length of the file. If not specified, reading continues until the end of the file. The valid range is [1, fileLength] in bytes.
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    entries
    Object
    The result of the file reading. 'res.entries' is an object where the key is the file path and the value is an object 'FileItem', representing the reading result of that file. Each 'FileItem' includes 'data' (file content) and 'errMsg' (error information) attributes.
    Structure Attributes of Entries
    Structure attributes
    Type
    Description
    path
    string
    File path
    path Structure Attributes
    Structure attributes
    Type
    Description
    data
    string/ArrayBuffer
    Version content
    errMsg
    string
    Error Message
    Sample Code
    const fs = wx.getFileSystemManager()
    // Read one or multiple files within a zip.
    fs.readZipEntry({
    filePath: 'wxfile://from/to.zip',
    entries: [{
    path: 'some_folder/my_file.txt', // File path within the zip
    encoding: 'utf-8', // Specifies the character encoding for reading the file. If 'encoding' is not passed, the file's binary content is read in ArrayBuffer format
    position: 0, // Start reading from a specified position in the file; if not specified, reading begins from the start of the file. The reading range should be a left-closed and right-open interval [position, position+length). The valid range is [0, fileLength - 1] in bytes.
    length: 10000, // Specify the length of the file. If not specified, reading continues until the end of the file. The valid range is [1, fileLength] in bytes.
    }, {
    path: 'other_folder/orther_file.txt', // File path within the zip
    }],
    success(res) {
    console.log(res.entries)
    // res.entries === {
    // 'some_folder/my_file.txt': {
    // errMsg: 'readZipEntry:ok',
    // data: 'xxxxxx'
    // },
    // 'other_folder/orther_file.txt': {
    // data: (ArrayBuffer)
    // }
    // }
    },
    fail(res) {
    console.log(res.errMsg)
    },
    })
    
    // Reads all files within the zip. A unified 'encoding' can be specified. 'Position' and 'length' can no longer be specified and default to 0 and the file length, respectively.
    fs.readZipEntry({
    filePath: 'wxfile://from/to.zip',
    entries: 'all'
    encoding: 'utf-8', // Uniformly specifies the character encoding for reading the file. If 'encoding' is not passed, the file's binary content is read in ArrayBuffer format.
    success(res) {
    console.log(res.entries)
    // res.entries === {
    // 'some_folder/my_file.txt': {
    // errMsg: 'readZipEntry:ok',
    // data: 'xxxxxx'
    // },
    // 'other_folder/orther_file.txt': {
    // errMsg: 'readZipEntry:ok',
    // data: 'xxxxxx'
    // }
    // }
    },
    fail(res) {
    console.log(res.errMsg)
    },
    })

    .removeSavedFile

    This method is used via FileSystemManager.removeSavedFile(Object object).
    Feature Description: Deletes the locally cached files saved under this mini program.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    Path for the files that need to be deleted.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail file not exist
    The file is not found in the specified tempFilePath.

    .rename

    This method is used via FileSystemManager.rename(Object object).
    Feature Description: Renames the file. It allows the file to be moved from oldPath to newPath.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    oldPath
    string
    -
    Yes
    Source file path, which can be a regular file or a directory.
    newPath
    string
    -
    Yes
    New file path.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail permission denied, rename ${oldPath} -> ${newPath}
    The specified source file or target file does not have write permissions.
    fail no such file or directory, rename ${oldPath} -> ${newPath}
    The source file does not exist, or the parent directory of the destination file path does not exist.

    .renameSync

    This method is used via FileSystemManager.renameSync(string oldPath, string newPath).
    Feature Description: The synced version of FileSystemManager.rename.
    Parameter and Description
    string oldPath: The source file path, which can be a regular file or a directory.
    string newPath: The path for the new file.

    .rmdir

    This method is used via FileSystemManager.rmdir(Object object).
    Feature Description: Deletes directory.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    dirPath
    string
    -
    Yes
    The path of directory to be deleted.
    recursive
    boolean
    false
    No
    Determines whether to recursively delete the directory. If set to true, it will delete the directory along with all its subdirectories and files.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail no such file or directory ${dirPath}
    The directory does not exist.
    fail directory not empty
    The directory is not empty.
    fail permission denied, open ${dirPath}
    The specified dirPath does not have write permissions.

    .rmdirSync

    This method is used via FileSystemManager.rmdirSync(string dirPath, boolean recursive).
    Feature Description: The synced version of FileSystemManager.rmdir.
    Parameter and Description:
    string dirPath: The path of the directory to be deleted.
    boolean recursive: Determines whether to recursively delete the directory. If set to true, it will delete the directory along with all its subdirectories and files.

    .saveFile

    This method is used via FileSystemManager.saveFile(Object object).
    Feature Description:Saves temporary files locally. Upon successful execution, the temporary file will be moved, rendering the tempFilePath unusable.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    tempFilePath
    string
    -
    Yes
    The path for temporary file storage.
    filePath
    string
    -
    No
    Path of files to be stored.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    savedFilePath
    number
    File path after storage
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail tempFilePath file not exist
    The file is not found in the specified tempFilePath.
    fail permission denied, open "${filePath}"
    The specified filePath does not have write permissions.
    fail no such file or directory "${dirPath}"
    Parent directory does not exist.

    .saveFileSync

    This method is used via number FileSystemManager.saveFileSync(string tempFilePath, string filePath).
    Feature Description: The synced version of FileSystemManager.saveFile.
    Parameter and Description:
    string tempFilePath: The path for temporary file storage.
    string filePath: The path of the file to be stored.
    Return Value: number savedFilePath, the path of the file after storage.

    .stat

    This method is used via FileSystemManager.stat(Object object).
    Feature Description: Gets the Stats object of the file.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    path
    string
    -
    Yes
    Path of file/directory
    recursive
    boolean
    false
    No
    Whether to recursively get the Stats information of each file in the directory.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    stats
    Stats/Object
    When recursive is false, res.stats is a Stats object. When recursive is true and path is a directory path, res.stats is an Object, with the key being the relative path rooted at path, and the value being the Stats object corresponding to that path.
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail permission denied, open ${path}
    The specified path does not have read permissions.
    fail no such file or directory ${path}
    The file does not exist.
    Sample Code
    When recursive is set to false.
    let fs = wx.getFileSystemManager()
    fs.stat({
    path: ${wx.env.USER_DATA_PATH}/testDir,
    success: res => {
    console.log(res.stats.isDirectory())
    }
    })
    
    When recursive is set to true.
    fs.stat({
    path: ${wx.env.USER_DATA_PATH}/testDir,
    recursive: true,
    success: res => {
    Object.keys(res.stats).forEach(path => {
    let stats = res.stats[path]
    console.log(path, stats.isDirectory())
    })
    }
    })

    .statSync

    This method is used via Stats|Object FileSystemManager.statSync(string path, boolean recursive).
    Feature Description: The synced version of FileSystemManager.stat.
    Parameter and Description:
    string path: File/directory path.
    boolean recursive: Determines whether to recursively retrieve the Stats information for each file in the directory.
    Return Value: Stats|Object stats. When recursive is false, res.stats is a Stats object. When recursive is true and path is a directory path, res.stats is an Object, with the key being the relative path rooted at path, and the value being the Stats object corresponding to that path.
    Sample Code
    When recursive is set to false.
    let fs = wx.getFileSystemManager()
    fs.stat({
    path: ${wx.env.USER_DATA_PATH}/testDir,
    success: res => {
    console.log(res.stats.isDirectory())
    }
    })
    When recursive is set to true.
    fs.stat({
    path: ${wx.env.USER_DATA_PATH}/testDir,
    recursive: true,
    success: res => {
    Object.keys(res.stats).forEach(path => {
    let stats = res.stats[path]
    console.log(path, stats.isDirectory())
    })
    }
    })

    .truncate

    This method is used via FileSystemManager.truncate(Object object).
    Feature Description: Executes a truncation operation on the file content.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    Path of the file to be truncated (local path)
    length
    number
    0
    No
    By default, the truncation position is 0. If the specified length value is less than the file length (measured in bytes), only the preceding number of bytes equal to the specified length will be retained in the file, and the remaining content will be deleted. If the specified length exceeds the file length, the file will be expanded, with the extended section being filled with null bytes ('\\0').
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Sample Code
    const fs = wx.getFileSystemManager()
    fs.truncate({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    length: 10, // Truncate the file starting from the 10th byte
    success(res) {
    console.log(res)
    }
    })

    .truncateSync

    This method is used via undefined FileSystemManager.truncateSync(Object object).
    Feature Description: Performs truncation operation on file content (synced version of truncate).
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    
    Yes
    Path of the file to be truncated (local path)
    length
    number
    0
    No
    By default, the truncation position is 0. If the specified length value is less than the file length (measured in bytes), only the preceding number of bytes equal to the specified length will be retained in the file, and the remaining content will be deleted. If the specified length exceeds the file length, the file will be expanded, with the extended section being filled with null bytes ('\\0').
    Return Value: undefined.
    Sample Code
    const fs = wx.getFileSystemManager()
    fs.truncateSync({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    length: 10, // Truncate the file starting from the 10th byte
    })
    This method is used via FileSystemManager.unlink(Object object).
    Feature Description: Deletes files.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    Path for the files that need to be deleted.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail permission denied, open ${path}
    The specified path does not have read permissions.
    fail no such file or directory ${path}
    The file does not exist.
    fail operation not permitted, unlink ${filePath}
    The filePath passed in is a directory.

    .unlinkSync

    This method is used via FileSystemManager.unlinkSync(string filePath).
    Feature Description: The synced version of FileSystemManager.unlink.
    Parameter and Description: string filePath, the path of the file to be deleted.

    .unzip

    This method is used via FileSystemManager.unzip(Object object).
    Feature Description: Decompresses files.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    zipFilePath
    string
    -
    Yes
    Source file path, which can only be a zip compressed file.
    targetPath
    string
    -
    Yes
    Path of destination directory.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail permission denied, unzip ${zipFilePath} -> ${destPath}
    The specified destination file path does not have write permissions.
    fail no such file or directory, unzip ${zipFilePath} -> "${destPath}
    The source file does not exist, or the parent directory of the destination file path does not exist.

    .write

    This method is used via FileSystemManager.write(Object object).
    Feature Description: Writes in file.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    fd
    string
    -
    Yes
    The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface.
    data
    string/ArrayBuffer
    -
    Yes
    The text or binary data to be written in.
    offset
    number
    -
    No
    Only effective when the data type is ArrayBuffer, it determines the part to be written in the ArrayBuffer, that is, the index in the ArrayBuffer, with the default value being 0.
    length
    number
    -
    No
    Only effective when the data type is ArrayBuffer, it specifies the number of bytes to be written, defaulting to the remaining bytes after offsetting the ArrayBuffer from 0 by the specified bytes at the offset value.
    encoding
    string
    utf8
    No
    Specifies the character encoding for the file to be written.
    position
    number
    -
    No
    Specifies the offset at the beginning of the file, that is, the position where the data is to be written. When position is not passed or a non-Number type value is passed, the data will be written at the current pointer location.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Valid values for encoding
    Value
    Description
    ascii
    -
    base64
    -
    binary
    -
    hex
    -
    ucs2/ucs-2/utf16le/utf-16le
    Reads in little-endian order.
    utf-8/utf8
    -
    latin1
    -
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    bytesWritten
    number
    The actual number of bytes written into the file (note, the number of bytes written may not necessarily be the same as the number of characters in the written string).
    Sample Code
    const fs = wx.getFileSystemManager()
    // Open the file
    fs.open({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    flag: 'a+',
    success(res) {
    // Write in files.
    fs.write({
    fd: res.fd,
    data: 'some text',
    success(res) {
    console.log(res.bytesWritten)
    }
    })
    }
    })

    .writeSync

    This method is used via FileSystemManager.writeFile(Object object).
    Feature Description: Synchronously writes in files.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    fd
    string
    -
    Yes
    The file descriptor. The fd is obtained through the FileSystemManager.open or FileSystemManager.openSync interface.
    data
    string/ArrayBuffer
    -
    Yes
    The text or binary data to be written in.
    offset
    number
    -
    No
    Only effective when the data type is ArrayBuffer, it determines the part to be written in the ArrayBuffer, that is, the index in the ArrayBuffer, with the default value being 0.
    length
    number
    -
    No
    Only effective when the data type is ArrayBuffer, it specifies the number of bytes to be written, defaulting to the remaining bytes after offsetting the ArrayBuffer from 0 by the specified bytes at the offset value.
    encoding
    string
    utf8
    No
    Specifies the character encoding for the file to be written.
    position
    number
    -
    No
    Specifies the offset at the beginning of the file, that is, the position where the data is to be written. When position is not passed or a non-Number type value is passed, the data will be written at the current pointer location.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Valid values for encoding
    Value
    Description
    ascii
    -
    base64
    -
    binary
    -
    hex
    -
    ucs2/ucs-2/utf16le/utf-16le
    Reads in little-endian order.
    utf-8/utf8
    -
    latin1
    -
    Parameters for object.success callback function: Object res.
    Attribute
    Type
    Description
    bytesWritten
    number
    The actual number of bytes written into the file (note, the number of bytes written may not necessarily be the same as the number of characters in the written string).
    Sample Code
    const fs = wx.getFileSystemManager()
    const fd = fs.openSync({
    filePath: ${wx.env.USER_DATA_PATH}/hello.txt,
    flag: 'a+'
    })
    const res = fs.writeSync({
    fd: fd,
    data: 'some text'
    })
    console.log(res.bytesWritten)

    .writeFile

    This method is used via FileSystemManager.writeFile(Object object).
    Feature Description: Writes files.
    Parameter and Description: Object
    Attribute
    Type
    Default value
    Required
    Description
    filePath
    string
    -
    Yes
    Path of file to be written in.
    data
    string/ArrayBuffer
    -
    Yes
    The text or binary data to be written in.
    encoding
    string
    utf8
    No
    Specifies the character encoding for the file to be written.
    success
    function
    -
    No
    Callback Function of Successful Interface Call
    fail
    function
    -
    No
    Callback Function of Failing Interface Call
    complete
    function
    -
    No
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    Valid values for object.encoding
    Value
    Description
    ascii
    -
    base64
    -
    binary
    -
    hex
    -
    ucs2/ucs-2/utf16le/utf-16le
    Reads in little-endian order.
    utf-8/utf8
    -
    latin1
    -
    Parameters for object.fail callback function: Object res
    Attribute
    Type
    Description
    errMsg
    string
    Error Message
    Valid values of res.errMsg
    Value
    Description
    fail no such file or directory, open ${filePath}
    The directory of the specified filePath does not exist.
    fail permission denied, open ${dirPath}
    The specified filePath does not have write permissions.

    .writeFileSync

    This method is used via FileSystemManager.writeFileSync(string filePath, string|ArrayBuffer data, string encoding).
    Feature Description: The synced version of FileSystemManager.writeFile.
    Parameter and Description:
    string filePath: The path of file to be appended.
    string|ArrayBuffer data: The text or binary data to be written in.
    string encoding: Specifies the character encoding for writing to the file.
    Valid Values for encoding
    Value
    Description
    ascii
    -
    base64
    -
    binary
    -
    hex
    -
    ucs2/ucs-2/utf16le/utf-16le
    Reads in little-endian order.
    utf-8/utf8
    -
    latin1
    -

    Error Code

    Caution:
    Unless otherwise specified, the error codes adhere to the following table.
    Error code
    Error Message
    Description
    1300001
    operation not permitted
    Operation not permitted (for instance, filePath is expected to receive a file but a directory is actually passed in).
    1300002
    no such file or directory ${path}
    The file/directory does not exist, or the parent directory of the target file path does not exist.
    1300005
    Input/output error
    Input/output stream is unavailable.
    1300009
    bad file descriptor
    Invalid file descriptor.
    1300013
    permission denied
    Permission error. The file is read-only or write-only.
    1300014
    Path permission denied
    The specified path does not have permissions.
    1300020
    not a directory
    The specified dirPath is not a directory, a case commonly seen when the parent path of the designated write path is a file.
    1300021
    Is a directory
    The specified path is a directory.
    1300022
    Invalid argument
    Invalid parameters. Consider checking if length or offset has exceeded their limits.
    1300036
    File name too long
    File name is too long.
    1300066
    directory not empty
    The directory is not empty.
    1300201
    system error
    The system interface call has failed.
    1300202
    the maximum size of the file storage limit is exceeded
    Insufficient storage space, or the file size has exceeded the limit (maximum 100 M).
    1300203
    base64 encode error
    Character encoding conversion has failed (for instance, base64 format error).
    1300300
    sdcard not mounted
    Android SD card mounting has failed.
    1300301
    unable to open as fileType
    Unable to open the file with the specified fileType.
    1301000
    permission denied, cannot access file path
    No access permission to the target path (usr directory).
    1301002
    data to write is empty
    The data written in is empty.
    1301003
    illegal operation on a directory
    This operation cannot be performed on a directory (for example, the specified filePath is an existing directory).
    1301004
    illegal operation on a package directory
    This operation cannot be performed on the code package directory.
    1301005
    file already exists ${dirPath}
    A file or directory with the same name already exists.
    1301006
    value of length is out of range
    The length passed in is invalid.
    1301007
    value of offset is out of range
    The offset passed in is invalid.
    1301009
    value of position is out of range
    The position value is out of limits.
    1301100
    store directory is empty
    The "store" directory is empty.
    1301102
    unzip open file fail
    Failed to open the compressed file.
    1301103
    unzip entry fail
    De-compression of individual files failed.
    1301104
    unzip fail
    De-compression failed.
    1301111
    brotli decompress fail
    Brotli de-compression failed (for instance, the specified compression algorithm does not match the actual compression format of the file).
    1301112
    tempFilePath file not exist
    The file is not found in the specified tempFilePath.
    1302001
    fail permission denied
    The specified fd path does not have read/write permissions.
    1302002
    excced max concurrent fd limit
    The number of file descriptors has reached its maximum limit.
    1302003
    invalid flag
    Invalid flag.
    1302004
    permission denied when open using flag
    Unable to open the file using the flag indicator.
    1302005
    array buffer does not exist
    ArrayBuffer has not been passed in.
    1302100
    array buffer is readonly
    The ArrayBuffer is read-only.

    Stats

    An object that describes the status of the file.

    Attribute

    Number mode: The type and access permissions of the file, corresponding to POSIX stat.st_mode.
    Number size: The size of the file, measured in bytes (B), corresponding to POSIX stat.st_size.
    Number lastAccessedTime: The most recent time the file was accessed or executed, represented as a UNIX timestamp, corresponding to POSIX stat.st_atime.
    Number lastModifiedTime: The most recent time the file was modified, represented as a UNIX timestamp, corresponding to POSIX stat.st_mtime.

    Method Set

    .isDirectory

    This method is used via boolean Stats.isDirectory().
    Feature Description: Determines whether the current file is a directory.
    Return Value: Boolean, indicating whether the current file is a directory.

    .isFile

    This method is used via boolean Stats.isFile().
    Feature Description: Determines whether the current file is a regular file.
    Return Value: Boolean, indicating whether the current file is a regular file.

    ReadResult

    Feature Description: File reading results. Returned via the FileSystemManager.readSync interface.
    Attributes:
    Number bytesRead, the actual number of bytes read.
    ArrayBuffer, the object of the buffer area being written, that is, the arrayBuffer of the interface parameter.

    WriteResult

    Feature Description: File writing results. Returned via the FileSystemManager.writeSync interface.
    Attributes: Number bytesWritten, the actual number of bytes written into the file (note, the number of bytes written may not necessarily be the same as the number of characters in the written string).
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support