sud.saveImageToPhotosAlbum
Save a local image to the system photo album.
javascript
sud.saveImageToPhotosAlbum(object)Parameters
Object object
| Property | Type | Required | Description |
|---|---|---|---|
| filePath | string | Yes | A local temporary or permanent image file path; network URLs are not supported |
| success | function | No | Called when the image is saved successfully |
| fail | function | No | Called when saving fails |
| complete | function | No | Called when the request finishes, whether successful or failed |
Return value
This asynchronous API reports its result through callbacks.
Callback parameters
success
Called when the image is saved successfully. No business result fields are defined.
fail
| Property | Type | Description |
|---|---|---|
| errCode | number | Error code |
| errMsg | string | Error message |
complete
Called after success or fail, with no arguments.
Usage notes
filePathmust identify a local image file that the current runtime can read. You can use a path fromtempFilePathsreturned by sud.chooseImage.- Download network images to a local file before passing their path to this API.
- Handle
failwhen a file is missing or unreadable, writing to the album fails, or the current environment does not provide this capability. Calling the API alone does not mean the image has been saved. - If the system requires album or storage permissions, the user must grant them before the image can be saved.
Example
Pass an existing local image path to saveLocalImage, such as res.tempFilePaths[0] returned by a successful image selection.
javascript
function saveLocalImage(filePath) {
sud.saveImageToPhotosAlbum({
filePath,
success: () => {
console.log('Image saved to the album');
},
fail: (err) => {
console.error('Saving failed', err.errCode, err.errMsg);
},
complete: () => {
console.log('Save request completed');
},
});
}