TwitPic has a restricted crossdomain.xml file preventing your Flash web applications from posting directly to the service.

Create a simple PHP script to proxy the request through a server that you do have access to!

Here is the code:

  $postfields = array();
  $postfields['username'] = $_POST['username'];
  $postfields['password'] = $_POST['password'];
  $postfields['message'] = $_POST['message'];
  $postfields['media'] = "@$file[tmp_name]";
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
  curl_setopt($curl, CURLOPT_HEADER, false);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
  curl_setopt($curl, CURLOPT_URL, $post_tweet_url);
  curl_setopt($curl, CURLOPT_POST, 3);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
  $result = curl_exec($curl);
  header ("content-type: text/xml");
  echo $result ;

Just create a PHP file with the contents above and replace the post URL from my previous example with the path to this script.


5 thoughts on “Post to TwitPic from Flash / Flex

  1. Thanks for the sample code Julien. The PHP is only required when building a web application. Adobe AIR uses local host for connection which doesn’t require a crossdomain.xml file. The policy file on TwitPic does require some form of server side code to submit.

Comments are closed.