Skip to content

sud.saveImageToPhotosAlbum ​

Save a local image to the system photo album.

javascript
sud.saveImageToPhotosAlbum(object)

Parameters ​

Object object ​

PropertyTypeRequiredDescription
filePathstringYesA local temporary or permanent image file path; network URLs are not supported
successfunctionNoCalled when the image is saved successfully
failfunctionNoCalled when saving fails
completefunctionNoCalled 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 ​

PropertyTypeDescription
errCodenumberError code
errMsgstringError message

complete ​

Called after success or fail, with no arguments.

Usage notes ​

  • filePath must identify a local image file that the current runtime can read. You can use a path from tempFilePaths returned by sud.chooseImage.
  • Download network images to a local file before passing their path to this API.
  • Handle fail when 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');
        },
    });
}