Empty METADATA for a received image using TweetPress API (3 posts)

  1. ma9ma
    Posted 6 years ago #

    Well, the title explains it all. I do have problems getting the metadata filled in wp_postmeta. This only appears when I try to add an attachment (image) using the TweetPress API (http://brandontreb.com/tweetpress/tweetpress-api/). After receiving the image (send with Twittelator for iPhone) I save the image to ../wp-content/uploads/ using

    move_uploaded_file($_FILES['media']['tmp_name'], $uploadFile)

    The file is correctly copied to the desired folder, with the permission set to 644. After this step I make the desired thumbs and smaller versions of the image using:

    image_resize( $resizefile, $tthumb ['w'], $tthumb ['h'], $tthumb ['c'])

    The smaller copies of the image are correctly created and placed in ../wp-content/uploads/, with permision set to 666.

    So far all goes fine. At this moment I try to add the image to the wp_post & wp_postmeta file using:

    $wp_filetype = wp_check_filetype(basename($fileName), null );
    $attachment = array(
       'post_mime_type' => $wp_filetype['type'],
       'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
       'post_content' => '',
       'post_author' => '1',
       'post_title' => $_POST['message'],
       'post_name' => $_POST['message'],
       'guid' => get_option ( 'siteurl' ) . '/wp-content/uploads/' . $fileName,
       'post_status' => 'inherit'
    $attach_id   = wp_insert_attachment( $attachment, $fileName, $post_id );
    $attach_data = wp_generate_attachment_metadata( $attach_id, $fileName );
    wp_update_attachment_metadata( $attach_id,  $attach_data );

    The attachment is correctly inserted into wp_post. Even the records made into wp_postmeta do exists. The only problem is the record with the "_wp_attachment_metadata" key. This one only contains "a:0:{}", instead of the expected long string. Because of this "empty" string I'm not able to edit the image inside WordPress. I get the error "Image data does not exist. Please re-upload the image.". Also WordPress thinks there are no thumbnails, which do exists.

    Who can help me out? Why is there no metadata? Are my steps correct? Thanks in advance.

  2. ma9ma
    Posted 6 years ago #

    No one?

  3. Austin Passy
    Posted 5 years ago #

    May have a look here: http://codex.wordpress.org/Function_Reference/wp_insert_attachment

    See this line:

    // you must first include the image.php file
    // for the function wp_generate_attachment_metadata() to work
    require_once(ABSPATH . "wp-admin" . '/includes/image.php');

    Just a thought. I am trying almost to do that same thing. Just pull the meta data from an image and apply it to a taxonmy that's part of the attachment. http://wordpress.org/support/topic/extracting-exif-and-inserting-into-taxonomy?replies=1

Topic Closed

This topic has been closed to new replies.

About this Topic