my.saveFile
This API is supported in base libraries 1.13.0 and later, and in mPaaS 10.1.32 and later. For earlier versions of the base library, you must ensure compatibility. For more information, see Mini Program base libraries.
This API saves a file to the local device. The total size of local files is limited to 10 MB. After a successful call to my.saveFile, the saved file is located in the /alipay/pictures/ folder on an Android device. On iOS, you cannot view the hidden folder path.
Input parameters
Name | Type | Required | Description |
apFilePath | String | Yes | File path |
success | Function | No | The callback function to run when the call succeeds. |
fail | Function | No | The callback function to run when the call fails. |
complete | Function | No | The callback function to run when the call is complete. This function runs whether the call succeeds or fails. |
Description of the success return value
Name | Type | Description |
apFilePath | String | The path where the file is saved. |
Code sample
my.chooseImage({
success: (res) => {
my.saveFile({
apFilePath: res.apFilePaths[0],
success: (res) => {
console.log(JSON.stringify(res))
},
});
},
});my.getFileInfo
This API is supported in base libraries 1.4.0 and later, and in mPaaS 10.1.32 and later. For earlier versions of the base library, you must ensure compatibility. For more information, see Mini Program base libraries.
Input parameters
Name | Type | Required | Description |
apFilePath | String | Yes | File path (local path). |
digestAlgorithm | String | No | The summary algorithm. Supported values are |
success | Function | No | The callback function to run when the call succeeds. |
fail | Function | No | The callback function to run when the call fails. |
complete | Function | No | The callback function to run when the call is complete. This function runs whether the call succeeds or fails. |
Success callback result
Name | Type | Description |
size | Number | File size. |
digest | String | The summary result. |
Code sample
my.getFileInfo({
apFilePath:'https://resource/apml953bb093ebd2834530196f50a4413a87.video',
digestAlgorithm:'sha1',
success:(res)=>{
console.log(JSON.stringify(res))
}
})my.getSavedFileInfo
This API is supported in base libraries 1.3.0 and later, and in mPaaS 10.1.32 and later. For earlier versions of the base library, you must ensure compatibility. For more information, see Mini Program base libraries.
This API retrieves information about a saved file.
Input parameters
Name | Type | Required | Description |
apFilePath | String | Yes | File path. |
success | Function | No | The callback function to run when the call succeeds. |
fail | Function | No | The callback function to run when the call fails. |
complete | Function | No | The callback function to run when the call is complete. This function runs whether the call succeeds or fails. |
Description of the success return value
Name | Type | Description |
size | Number | File size. |
createTime | Number | The timestamp of the creation time. |
Code sample
You can only use my.getSavedFileInfo with paths that were saved using my.saveFile.
var that = this;
my.chooseImage({
success: (res) => {
console.log(res.apFilePaths[0], 1212)
my.saveFile({
apFilePath: res.apFilePaths[0],
success: (result) => {
console.log(result, 1212)
my.getSavedFileInfo({
apFilePath: result.apFilePath,
success: (resu) => {
console.log(JSON.stringify(resu))
that.filePath = resu
}
})
},
});
},
});my.getSavedFileList
This API is supported in base libraries 1.13.0 and later, and in mPaaS 10.1.32 and later. For earlier versions of the base library, you must ensure compatibility. For more information, see Mini Program base libraries.
This API retrieves a list of all saved files.
Input parameters
Name | Type | Required | Description |
success | Function | No | The callback function to run when the call succeeds. |
fail | Function | No | The callback function to run when the call fails. |
complete | Function | No | The callback function to run when the call is complete. This function runs whether the call succeeds or fails. |
Success return value description
Name | Type | Description |
fileList | List | File list. |
File object properties
Name | Type | Description |
size | Number | File size. |
createTime | Number | Creation time. |
apFilePath | String | File path. |
Code sample
my.getSavedFileList({
success:(res)=>{
console.log(JSON.stringify(res))
}
});my.removeSavedFile
This API is supported in base libraries 1.13.0 and later, and in mPaaS 10.1.32 and later. For earlier versions of the base library, you must ensure compatibility. For more information, see Mini Program base libraries.
This API deletes a saved file.
Input parameters
Name | Type | Required | Description |
apFilePath | String | Yes | File path. |
success | Function | No | The callback function to run when the call succeeds. |
fail | Function | No | The callback function to run when the call fails. |
complete | Function | No | The callback function to run when the call is complete. This function runs whether the call succeeds or fails. |
Code sample
my.getSavedFileList({
success:(res)=>{
my.removeSavedFile({
apFilePath:res.fileList[0].apFilePath,
success:(res)=>{
console.log('remove success')
}
})
}
});my.openDocument
my.openDocument(Object object)
You can preview local PDF files.
Input parameters
Object object
Property | Type | Default | Required | Compatibility | Description |
filePath | String | - | Yes | - | File path (temporary file, cache file, or user file). |
fileType | String | - | Yes | - | File type. Valid value: pdf. |
success | Function | - | No | - | The callback function to run when the call succeeds. |
fail | Function | - | No | - | The callback function to run when the call fails. |
complete | Function | - | No | - | The callback function to run when the call is complete. Note This function runs whether the call succeeds or fails. |
Error codes
The fail callback returns an Object. The error property of this object contains the error code, and the errorMessage property contains the error message.
Error code | Error message | Solutions |
4011 | Invalid path | Check if the filePath parameter is correct. For more information, see the type and description of the filePath parameter. |
4012 | The file does not exist | Check if the file specified by `filePath` exists. |
4013 | This file type is not supported | Check if the `fileType` parameter is correct. For more information, see the description of the fileType parameter. |
Code sample
my.openDocument({
filePath: `${my.env.USER_DATA_PATH}/test.pdf`,
fileType: 'pdf',
success: (res) => {
console.log(res);
},
fail: (err) => {
console.log(err);
},
});Tip
You can download a PDF file using my.downloadFile and use the local temporary file path as the filePath parameter.