# Mini-Program File Management

# 1. Convert finfile path to absolute path

Supported App Types

Mini-Program✅ Mini-Game✅ H5 Application✅

In some scenarios, we obtain a finfile path but cannot retrieve the file data. This method can be used to convert it to an absolute path. Note: The finfile protocol file must exist; if it does not exist, null will be returned.

For example, when using the Mini-Program's forwarding feature, the returned image path is a Mini-Program file path. This method can convert it to an absolute path, allowing retrieval of the image data before invoking third-party sharing. Another example is in custom APIs, where parameters can pass Mini-Program file paths. The Host-App can use this method to convert them to absolute paths and then access the file data.

Main Process

    /**
     *  Convert finfile path to absolute path
     *  @param context
     *  @param appId
     *  @param filePath  finfile path
     */
    fun getFinFileAbsolutePath(context: Context, appId: String, filePath: String): String?

# Usage Example

val appletTempPath = FinAppClient.appletApiManager.getFinFileAbsolutePath(this,"60964a900f0ca30001292da1","finfile://tmp_4d412db8426d8deede4be6eac5a82476.jpg")

Child Process

    /**
     * Convert finfile path to absolute path
     *
     * @param finFilePath Mini-Program protocol path
     */
    fun getFinFileAbsolutePath(finFilePath: String) : String?

# Usage Example

val path = FinAppProcessClient.appletProcessApiManager.getFinFileAbsolutePath("finfile://tmp_4d412db8426d8deede4be6eac5a82476.jpg")

# 2. Generate finfile protocol path

Supported App Types

Mini-Program✅ Mini-Game✅ H5 Application✅

There are three types of finfile protocol paths in Mini-Programs: finfile://tmp_, finfile://store_, finfile://usr/. The tmp type path is saved under the Mini-Program's runtime directory and will be cleared upon the next cold start of the Mini-Program. The store path is persistently saved and only deleted when the Mini-Program is removed. The usr type path is also persistently saved but allows custom filenames and directories.

This function can generate a finfile protocol path by inputting a filename and the desired path type for use within the Mini-Program. However, the file may not necessarily exist; it should be combined with other APIs to write content to the corresponding file.

     /**
     * Generate a FinFile protocol path based on the path type
     * @param filePath File path. When pathType is usr, folders are supported, e.g., /aaa/bbb.jpg
     * @param pathType Path type, an enum variable: usr, tmp, store
     */
    fun generateFinFilePath(filePath: String, pathType: FinFilePathType): String?

# Usage Example

val appletTempPath = FinAppClient.appletApiManager.generateFinFilePath("bbc/bbab/test.jpg", FinFilePathType.USR)

# 3. Convert finfile path to absolute path (file may not exist)

Supported App Types

Mini-Program✅ Mini-Game✅ H5 Application✅

In some scenarios, we obtain a finfile path, but the file does not actually exist at that path. We may want to convert it to an absolute path and then save the file there for use.

For example, if we want to save an image under the Mini-Program's path, we can first call the API: generateFinFilePath to generate a finfile path, then call this API to generate an absolute path (e.g., converting finfile://usr/bbc/bbab/test.jpg to an absolute path; this API will automatically create the first two levels of directories, bbc/bbab/). After generating the absolute path, the image file can be saved to this path.

    /**
     *  Convert finfile path to absolute path
     *  @param context
     *  @param appId
     *  @param filePath  finfile path
     */
    fun getFinFileAbsolutePathCanNoExist(context: Context, appId: String, filePath: String): String?

# Usage Example

val appletTempPath = FinAppClient.appletApiManager.getFinFileAbsolutePathCanNoExist(this,"60964a900f0ca30001292da1","finfile://usr/bbc/bbab/test.jpg")

# 4. Get the path of the Mini-Program temporary file storage directory

Supported App Types

Mini-Program✅ Mini-Game✅ H5 Application✅

# API

/**
 * Get the path of the Mini-Program temporary file storage directory
 *
 * @param context Context
 * @param appId Mini-Program ID
 * @return Path of the Mini-Program temporary file storage directory
 */
fun getAppletTempPath(context: Context, appId: String): String?

# Usage Example

    # 5. Get the path of the Mini-Program source code storage directory

    Supported App Types

    Mini-Program✅ Mini-Game✅ H5 Application✅

    # API

    /**
     * Get the path of the Mini-Program source code storage directory
     *
     * @param context Context
     * @param appId Mini-Program ID
     * @return Path of the Mini-Program source code storage directory
     */
    fun getAppletSourcePath(context: Context, appId: String): String?
    

    # Usage Example

      © FinClip with ❤ , Since 2017