tencent cloud

All product documents
Tencent Cloud Super App as a Service
File System
Last updated: 2025-02-24 17:10:39
File System
Last updated: 2025-02-24 17:10:39
The file system in mini games provides a storage solution isolated by mini game and user dimensions, along with a set of management APIs. You can learn the user’s subscription status for related template messages using getFileSystemManager. All file system management operations are performed through the FileSystemManager.
var fs = wx.getFileSystemManager()
Files are mainly divided into two types:
Code package files: These are files added to the project directory.
Local files: These are files generated locally through API calls or downloaded from the network and stored locally.
Local files are further divided into three types:
Local temporary files: These are temporary files that can be reclaimed at any time. There is no storage size limit.
Local cache files: These are files generated by caching local temporary files through APIs. The directory and file names cannot be customized. Together with local user files, a mini program (including mini games) can store up to 200 MB.
Local user files: These are files generated by caching local temporary files through APIs, allowing custom directories and file names. Together with local cache files, a mini program (including mini games) can store up to 200 MB.

Code package files

Due to the size limitation of code package files, they are suitable for files needed during the initial load. For larger files or files that need to be dynamically replaced, it is recommended to download them locally after the mini game starts.

Access to code package files

Code package files are accessed by writing the file path starting from the project root directory. Relative paths are not supported. For example,/a/b/c and a/b/c are valid, while./a/b/c and ../a/b/c are not.

Modify code package files

Files within the code package cannot be dynamically modified or deleted after running. Modifying code package files requires republishing the version.

Local files

Local files refer to a separate file storage area created when a mini game is added to a user's phone, isolated by user dimension. This means that on the same phone, each user cannot access files of other logged-in users, and files between different appIds for the same user cannot be accessed.
The file paths for local files are in the following format:
{{protocol name}}://file path
Note:
The protocol is "wxfile" on iOS/Android clients and "http" in the developer tools. Developers do not need to worry about this difference and should not hardcode the complete file path in the code.

Local temporary files

Local temporary files can only be generated by calling specific APIs and cannot be directly written. They are only guaranteed to be valid during the current lifecycle and may not be available after a restart. Therefore,do not store local temporary file paths for future use.If you need to use them later, convert them to local cache files or local user files using FileSystemManager.saveFile or FileSystemManager.copyFile.

Example:
wx.chooseImage({
success: function (res) {
var tempFilePaths = res.tempFilePaths // each entry in tempFilePaths is a local temp file path
}
})

Local cache files

Local cache files can only be generated by calling specific APIs and cannot be directly written. They remain available after a restart. Local cache files can only be obtained by saving local temporary files using the FileSystemManager.saveFile.

Example:
fs.saveFile({
tempFilePath: '', // Pass in a local temporary file path
success(res) {
console.log(res.savedFilePath) // res.savedFilePath is a local cache file path
}
})

Local user files

A user file directory is provided to developers, where they have full read and write permissions. The path to this directory can be obtained using wx.env.USER_DATA_PATH.

Example:
// Create a file hello.txt in the local user file directory and write "hello, world" to it
const fs = wx.getFileSystemManager()
fs.writeFileSync(`${wx.env.USER_DATA_PATH}/hello.txt`, 'hello, world', 'utf8')

Read & write permissions

API/Components
Read
Write
Code package files
Yes
No
Local temporary documents
Yes
No
Local cache files
Yes
No
Local user files
Yes
Yes

Cleanup strategy

Local temporary files: These files are only guaranteed to be available during the current lifecycle of the mini game. Once the mini game is closed, these files may be cleaned up, meaning they may not be available the next time the game is started.
Local cache files and local user files: The cleanup timing for these files is the same as for code package files. They will only be cleaned up when the code package itself is cleaned up.

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

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 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon