my.saveFile

Save file in a local position (total capacity of local file size is limited to 10 MB).

Supported types of mini programs: DSL, H5+

Sample Code

copy
my.chooseImage({
  success: (res) => {
    my.saveFile({
      apFilePath: res.apFilePaths[0],
      success: (res) => {
        console.log(JSON.stringify(res))
      },
    });
  },
});

Parameters

Object type with the following attributes:

Property

Type

Required

Description

toDisk

Boolean

No

Indicates whether to save the mini program local files to the system storage:

  • true: To save files to the system storage.
  • false: (Default value) To save files to the app internal storage.

apFilePath

String

Yes

File path.

Note:

  • When the toDisk parameter is true, support local temporary files, local cache files, and local user files.
  • When the toDisk parameter is false, support support local temporary files, local cache files.

success

Function

No

Callback function upon call success.

fail

Function

No

Callback function upon call failure.

complete

Function

No

Callback function upon call completion (to be executed upon either call success or failure).

Success Callback Function

The incoming parameter is of the Object type with the following attributes:

Property

Type

Description

apFilePath

String

File save path.

Note: When the toDisk parameter is true, this parameter will not be returned in the callback upon successful JSAPI invocation.

rror code

Error code

Error message

Further action

2

Invalid parameters

Refer to the previous Parameters table to ensure that all parameters are specified correctly, and that all required parameters are provided.

11

User cancelled

Please instruct users to choose a file corretly.

12

file does not exist

Refer to the previous Parameters table to ensure that all parameters are specified correctly, and that all required parameters are provided.

13

Save file failed

Refer to the previous Parameters table to ensure that all parameters are specified correctly, and that all required parameters are provided.