Blip raw post data and drupal_http_request

mediacurrent-in... - May 19, 2008 - 01:36
Project:Media Actions
Version:5.x-1.0
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

I've got some code written to replace curl in the _media_actions_bliptv_send function. It builds a MIME-encoded POST. But, I keep getting an internal server error when posting to blip. Blip's not returning any status. So, wanted to know if you were able to track down what the raw post data to blip should look like when you were building this module? For reference, the drupal_http_request code is below...

$username = 'asdf';
$password = 'asdf';
$local_video_field_name = 'field_video_file';
$remote_video_field_name = 'file';

//$local_video_field = &$node->$local_video_field_name;
//$local_video = array_shift($local_video_field);

if ($local_video['flags']['delete']) {
//video file is being deleted
return _media_actions_bliptv_delete($node, $params);
}

$file_path = 'files/media/video/CrestWS_PGCW0287-300k_2.wmv';//$local_video['filepath'];
$file_name = 'CrestWS_PGCW0287-300k.wmv';//$local_video['filename'];

//need to make MIME-encoded POST, so put all data in a MIME part and wrap $post_data fields with appropriate
//MIME structure
$boundary = '-----------'.mt_rand(1,10000);
$header = array();
$header['Content-Type'] = 'multipart/form-data; boundary='.$boundary;

// Upload file to blip.tv
$post_data['file'] = file_get_contents($file_path);//"@" . $file_path;
$post_data['description'] = $file_name . $edit['signature']; // Any valid text or HTML
$post_data['title'] = 'Blip test from operation';//$node->title; // Maximum length 255. No HTML.
$post_data['post'] = '1'; // Required: must set this to 1
$post_data['skin'] = 'xmlhttprequest';
$post_data['item_type'] = 'file';
$post_data['license'] = -1;//$edit['license']; // Defaults to "-1" or "No license"
$post_data['categories_id'] = -1; // "-1" means no category. Never use a value of "0".
$post_data['userlogin'] = $username; // valid username
$post_data['password'] = $password; // valid password
if (isset($blip_file_id)) {
$post_data['id'] = $blip_file_id; // update the file
}

$data = array();
$data[] = '';
foreach($post_data as $key => $value){
if($key == 'file'){
$data[] = $boundary;
$data[] = 'Content-Disposition: form-data; name="'.$key.'"; filename="'.$file_path.'"';
$data[] = 'Content-Type: application/octet-stream';//.mime_content_type($file_path);
$data[] = '';
$data[] = $value;//base64_encode($value);
}else{
$data[] = $boundary;
$data[] = 'Content-Disposition: form-data; name="'.$key.'"';
$data[] = '';
$data[] = $value;
}
}

$str_data = implode("\r\n", $data);

$response = new stdClass();

$timeout = intval($edit['timeout']);
set_time_limit($timeout);

/*
* drupal_http_request implementation, mediacurrent-interactive, pchason 051408
* replaces curl
*/
//http://uploads.blip.tv
$response = drupal_http_request("http://uploads.blip.tv", $header, 'POST', $str_data);

#1

pfournier - June 14, 2008 - 16:41

Hi,
I have myself tried to use drupal_http_request, but with no success. If you have an Apache + PHP installation you can replace the blip.tv URL in the CURL implementation to the URL of your server, and do print_r($_POST). It may help you see if there is any difference between your implementation and the CURL one.

 
 

Drupal is a registered trademark of Dries Buytaert.