Skip to main content
Version: v1.0

File System

Introduction​

The Zepp OS Mini Program file system directory is divided into two parts, the /assets resource directory and the /data data directory.

The /assets directory holds the Mini Program's resources, and only readable operations can be performed in this directory.

info

The hmFS.stat_asset and hmFS.open_asset APIs use the /assets resource directory as the root directory.

Each Mini Program has its own /data directory, which can be read and written to, and each Mini Program will be isolated from each other.

info

Except for the hmFS.stat_asset and hmFS.open_asset APIs, the rest of the file system operations APIs use /data as the root directory.

/assets resource directory​

There are two /assets directory concepts that need to be clarified here.

  • The /assets directory in the directory structure for Mini Program development
  • Mini Program file system /assets directory

The two are very closely related, see an example.

The following figure shows the /assets directory in the directory structure for Mini Program development.

.
assets
├── gtr-3
│ ├── icon.png
│ └── image
│ └── logo.png
├── gtr-3-pro
│ ├── icon.png
│ └── image
│ └── logo.png
└── gts-3
│ ├── icon.png
│ └── image
│ └── logo.png
└── raw
└── data.txt

After the Mini Program is compiled and built, the Mini Program file system /assets directory corresponds to the following.

.
assets
├── icon.png
└── image
│ └── logo.png
└── raw
└── data.txt

For example, you need to access raw/data.txt.

page.js
Page({
build() {
const fileId = hmFS.open_asset('raw/data.txt', hmFS.O_RDONLY)
}
})
tip

/raw is an agreed directory name, the /raw directory will be copied to the Mini Program /assets directory during compilation and packaging.

File System API Caution​

caution

All file system APIs need to be called within the lifecycle of an App or Page, otherwise an error will occur.

Error Code​

Error CodeDescription
0Operation success
-1Disk Error
-2Internal Error
-3Disk Error
-4Path not found
-5Path not found
-6Incorrect path format
-7No access rights
-8No access rights
-9Invalid file handle
-10Disk Write Protection
-11Disk Error
-12Insufficient disk space
-13Insufficient disk space
-14Execution Failure
-15No access rights
-16Disk Error
-17Open too many files at the same time
-18Invalid incoming parameters