Skip to content

Image block: Blob is not always a temporary image, it could be an external final image from 3rd party implementation #60688

@jasperck

Description

@jasperck

What problem does this address?

Currently, core/image sees blob as a temporary image, whereas sometimes a blob could be a final image in 3rd party implementations, for example, we handle image upload and host it on our end and wanted to pass a blob to core/image to display it correctly, it won't work. Passing some kind of ID would work around the first condition but will then break the isExternalImage condition.

/**
 * Is the URL a temporary blob URL? A blob URL is one that is used temporarily
 * while the image is being uploaded and will not have an id yet allocated.
 *
 * @param {number=} id  The id of the image.
 * @param {string=} url The url of the image.
 *
 * @return {boolean} Is the URL a Blob URL
 */
const isTemporaryImage = ( id, url ) => ! id && isBlobURL( url );

/**
 * Is the url for the image hosted externally. An externally hosted image has no
 * id and is not a blob url.
 *
 * @param {number=} id  The id of the image.
 * @param {string=} url The url of the image.
 *
 * @return {boolean} Is the url an externally hosted url?
 */
export const isExternalImage = ( id, url ) => url && ! id && ! isBlobURL( url );

I feel like we unblock Image block for this case, thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions