title: Uploading BitmapData using Facebook Graph Api
body: <p>I've been looking around the internet on how to use the PostRequest class given by the Facebook in their Graph Api, but I couldn't find anything on it. I'm wondering how to use it to upload a bitmapdata. It just doesn't seem to be moving at all.</p>
  
  <p>I used this code and it worked:</p>
  
  <pre><code>private function getSnapshot(e:MouseEvent):void 
  {
      bmd = new BitmapData(vidDisplay.width, vidDisplay.height); 
      bmd.draw(vidDisplay);
      vidDisplay.previewImg.source = new Bitmap(bmd);
  
      isSnapshot = true;
  
      vidDisplay.upload_btn.enabled = true;
      vidDisplay.caption_txt.enabled = true;
      vidDisplay.browse_btn.enabled = false;
  }
  
  protected function upload(w:MouseEvent):void 
  {
      var img:* = (isSnapshot) ? bmd : fileRef ;
      var values:Object = {message:vidDisplay.caption_txt.text, fileName:'FILE_NAME', image:img};
  
      fb.callApi("post", "me", "photos", values);
  
      vidDisplay.caption_txt.text = "";
      vidDisplay.upload_btn.enabled = false;
      vidDisplay.snapShot_btn.enabled = false;
  }
  </code></pre>
  
  <p>However, when I tried to make a whole function to take a picture and upload straightaway, it doesn't work. At first, it was like this:</p>
  
  <pre><code>private function doTakeSnapshot(con:MovieClip, cap:String = null):void
  {
      ExternalInterface.call("doAlert", "doTakeSnapshot");
  
      var bmd:BitmapData = new BitmapData(con.width, con.height);
      bmd.draw(con);
  
      if (cap == null) { cap = "Check out my photo!"; }
      var values:Object = {message:cap, image:bmd};
  
      doCallApi("post", "me", "photos", values);
  }
  </code></pre>
  
  <p>Then I tried with the PostRequest:</p>
  
  <pre><code>private function doTakeSnapshot(con:MovieClip, cap:String = null):void
  {
      ExternalInterface.call("doAlert", "doTakeSnapshot");
  
      var bmd:BitmapData = new BitmapData(con.width, con.height);
      bmd.draw(con);
  
      if (cap == null) { cap = "Check out my photo!"; }
  
      var ba:ByteArray = PNGEncoder.encode(bmd);
      var pr:PostRequest = new PostRequest();
      //var ba:ByteArray = pr.getPostData();
      pr.createPostData();
      pr.writePostData("fileName", "testtest");
      pr.writeFileData("fileName", ba, "image/png");
      pr.close();
  
      var byteArray:ByteArray = pr.getPostData();
      ExternalInterface.call("doAlert", "ByteArray = " + byteArray);
  
      var values:Object = {message:cap, image:byteArray};
  
      doCallApi("post", "me", "photos", values);
  }
  </code></pre>
  
  <p>Both doesn't work, which puzzles me. The first one worked without encoding it in any way, so I don't get why it doesn't work when I try to just call it like that. Any help?</p>