IPTC metadata mapping for XML-RPC wp.uploadFile (1 post)

  1. chrismichaelscott
    Posted 2 years ago #

    I am attempting to send images to a WordPress system using the XML-RPC API, and to use the IPCT caption field as the description of the new media asset.

    When uploading a JPG/TIFF using the XML-RPC API the description and caption fields are left blank. If the same file is uploaded using the GUI (ultimately wp-admin/async-upload.php) then the IPTC metadata is extracted and the caption mapped to the attachment's content field.
    As there is no metadata field for the wp.uploadFile payload, it is not possible to extract that metadata before upload.

    I am not sure if this is expected behaviour or a bug but I am inclined towards a bug because:

    In the mw_newMediaObject function in class-wp-xmlrpc-server.php, a call is made to extract the IPCT fields:

    wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );

    If one were to inspect the output from wp_generate_attachment_metadata they would find that the IPTC fields have been extracted successfully. I dumped the output from a test image as:

        [width] => 664
        [height] => 899
        [hwstring_small] => height='96' width='70'
        [file] => 2012/11/te_14938311.jpeg
        [image_meta] => Array
                [aperture] => 0
                [credit] => Luis Alvarez
                [camera] =>
                [caption] => Jurgen Melzer, of Austria, reacts after winning a set against Donald Young during a tennis match at the Legg Mason Tennis Classic, Wednesday, Aug. 3, 2011, in Washington. (AP Photo/Luis M. Alvarez)
                [created_timestamp] => 0
                [copyright] =>
                [focal_length] => 0
                [iso] => 0
                [shutter_speed] => 0
                [title] =>

    However the image in the media library showed no caption/description.

    It is possible to resolve this problem by setting the post content, in a similar way to async-upload.php, but that seams like the wrong approach:

    if ( $image_meta = @wp_read_image_metadata($upload['file']) ) {
                            if ( trim( $image_meta['caption'] ) )
                                    $content = $image_meta['caption'];
                    // Construct the attachment array
                    // attach to post_id 0
                    $post_id = 0;
                    $attachment = array(
                            'post_title' => $name,
                            'post_content' => $content,
                            'post_type' => 'attachment',
                            'post_parent' => $post_id,
                            'post_mime_type' => $type,
                            'guid' => $upload[ 'url' ]


    1) Is this a bug or expected behaviour?
    2) Are there any plans to allow developers to upload files via the XML-RCP API and provided captions/description in the process?
    3) Are there any work arounds to add the metadata to the media asset after it has been uploaded (still using the Web service)?

    Many thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 2 years ago by chrismichaelscott
  • This topic is not resolved
  • WordPress version: 3.4.2