my.chooseImage
Choose an image from the camera or gallery of a device.
Supported types of mini programs: DSL, H5+
Sample Code
copy
my.chooseImage({
success: (res) => {
img.src = res.apFilePaths[0];
},
});Parameters
| Property | Type | Required | Description |
| sourceType | String Array | No | Camera or album, [‘camera’,‘album’] by default. |
| 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 |
| apFilePaths | String Array | Image file description. |
Error Code
Error code | Error message | Further action |
2 | Invalid param : sourceType = ${sourceType} | Refer to the previous Parameters table to ensure that all parameters are specified correctly, and that all required parameters are provided. |
11 | User canceled | User cancels this image choosing operation. No action required in this normal flow. |
14 | No camera access rights | Please enable the device camera access permissions. |
15 | No album access rights | Please enable the device gallery access permissions. |