Pular para o conteúdo principal

getMediaFile

Callable


  • Returns the given variation of the provided MediaObject.

    @example

    Getting the optimized or original file of the given MediaObject.

    import Starlight, { getMediaFile } from '@starlightcms/js-sdk'

    const response = await Starlight.posts.entries.get('foo')

    // `info.featured_image` is the path of an arbitrary Media content field.
    const file = getMediaFile(response.data.data.info.featured_image)

    Parameters

    • optionalmedia: MediaObject

      The MediaObject to analyze. If undefined, the function will also return undefined.

    • optionalvariation: string | string[]

      A string or array of strings with the variation name that should be returned. If an array is given, the first variation found will be returned.

    Returns undefined | MediaFile

    The MediaFile of the first given variation found. If the provided variations weren’t found, or if no variation parameter was provided, returns the optimized variation file (if it exists) or the original file. Returns undefined if no media object is provided.