• I would like to convert image format to WebP while uploading an image via REST API.

    Usually, I use this function to generate WebP format from the original image resource while uploading media via GUI.

    add_filter( 'wp_generate_attachment_metadata', 'custom_function_generate_webp_format', 10, 2 );

    But this function does not work with the REST API Uploading Media method, which is described in the link below.

    https://developer.www.ads-software.com/rest-api/reference/media/#create-a-media-item

    Any idea that can convert the image format while uploading with REST API?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    The API does call wp_generate_attachment_metadata(), so we’d expect the filter hook to still work. I think the trouble is your webp conversion code doesn’t get loaded with API requests. The API controller even has to explicitly require_once the core media and image resources because even they are not normally loaded for API requests. Or your code might be loaded, but other dependent resources may be missing.

    Check your error log for clues to what resources might be missing. Anything missing could be explicitly loaded through the “rest_api_init” action.

Viewing 1 replies (of 1 total)
  • The topic ‘Convert image format to WebP while uploading an image via REST API’ is closed to new replies.