• Hey all,

    I have been working on some code for a site that does some uploading of images and creates a post.

    All is mostly OK, but for some reason when I upload images I do not always get a return from my code.

    $imagedata = array(
        'name'  => basename($image),
        'type'  => 'image/jpg',
    	'bits' => new IXR_Base64(file_get_contents($image)),
    	'overwrite' => 1);
    
    	$client->query( 'wp.uploadFile', '', $user, $passwd, $imagedata);
    	$ret = $client->getResponse();
    print_r($ret);

    Sometimes I do, and sometimes I dont, its really confusing me.

    Each time the image is always actually uploaded into wordpress as I can see it in the Media library, I just don’t get a response object from the API call.

    Considering that I need the ID to build a slideshow in the actual post, its a tad annoying.

    There are no errors thrown on the PHP page, and nothing in the errors logs for the site either.

    Does anyone have any ideas of where to look/figure this one out?

Viewing 1 replies (of 1 total)
  • Thread Starter mikehobin

    (@mikehobin)

    ok, I tracked this issue down for those that care.

    The issue is caused by the SmishIt Plugin not responding as quickly as WordPress natively.

    Turn off smushit and all is OK, turn it back on and the issue keeps occuring.

    so here is my fix

    $imagedata = array(
        'name'  => basename($image),
        'type'  => 'image/jpg',
    	'bits' => new IXR_Base64(file_get_contents($image)),
    	'overwrite' => 1);
    
    	$client->query( 'wp.uploadFile', '', $user, $passwd, $imagedata);
    	$ret = $client->getResponse();
    
    	while (!is_array($ret)) {
    
    		usleep(500000); // sleep for half a second
    		$ret = $client->getResponse();
    	}
Viewing 1 replies (of 1 total)

The topic ‘wp.uploadFile not returning struct’ is closed to new replies.