Skip to content

sud.previewImage ​

Preview a list of images and optionally specify which image to display first.

javascript
sud.previewImage(object)

Parameters ​

Object object ​

PropertyTypeRequiredDescription
currentstringNoAddress of the image to display first; it should be an entry in urls. Specify it explicitly when possible
urlsArray<string>YesA nonempty list of image addresses to preview
successfunctionNoCalled when the preview request succeeds
failfunctionNoCalled when the preview request 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 preview request is accepted. No business result fields are defined. This callback does not mean that all images have finished loading or that the user has closed the preview.

fail ​

PropertyTypeDescription
errCodenumberError code
errMsgstringError message

complete ​

Called after success or fail, with no arguments. It does not indicate that the preview page has closed.

Usage notes ​

  • Ensure that urls is nonempty and set current to one of its entries. Avoid relying on how omitted or invalid values are handled.
  • Image addresses can be local file paths or network URLs supported by the current runtime. Supported address formats depend on the runtime. Local files must be readable and network images must be accessible.
  • Image loading errors may be shown inside the preview without triggering this request's fail callback.
  • This API does not provide a preview-close callback or return the last image viewed by the user.

Example ​

Pass an existing list of image addresses to previewImages, such as res.tempFilePaths returned by sud.chooseImage.

javascript
function previewImages(urls) {
    if (!urls || urls.length === 0) {
        return;
    }
    sud.previewImage({
        current: urls[0],
        urls,
        success: () => {
            console.log('Preview request accepted');
        },
        fail: (err) => {
            console.error('Preview request failed', err.errCode, err.errMsg);
        },
        complete: () => {
            console.log('Preview request completed');
        },
    });
}