title: C#: Upload Photo To Twitter From Unity
body: <p>currently I am working with unity. In this project, I need to post some status with image to twitter. However, I got a problem to upload the image to the Twitter.</p>
  
  <p>Here is the code, which I used to upload the Image:</p>
  
  <pre><code>private const string UploadMediaURL = "https://upload.twitter.com/1.1/media/upload.json";
      public static IEnumerator UploadMedia(string consumerKey, string consumerSecret, string filePath, AccessTokenResponse response){
                  Dictionary&lt;string, string&gt; mediaParameters = new Dictionary&lt;string, string&gt;();
                  mediaParameters.Add("media", System.Convert.ToBase64String(File.ReadAllBytes(filePath)));
  
                  // Add data to the form to post.
                  WWWForm mediaForm = new WWWForm();
                  mediaForm.AddField("media", System.Convert.ToBase64String(File.ReadAllBytes(filePath)));
  
                  print (System.Convert.ToBase64String (File.ReadAllBytes (filePath)));
  
                  // HTTP header
                  var mediaHeaders = new Hashtable();
                  mediaHeaders["Authorization"] = GetHeaderWithAccessToken("POST", UploadMediaURL, consumerKey, consumerSecret, response, mediaParameters);
  
                  WWW mw = new WWW(UploadMediaURL, mediaForm.data, mediaHeaders);
                  yield return mw;
  
                  if (!string.IsNullOrEmpty (mw.error)) {
                      Debug.Log(string.Format("PostTweet - failed. {0}"));
                  } else {
                      SetMediaWeb(mw);
                  }
              }
  </code></pre>
  
  <p>When I call above method, I got bellow error:</p>
  
  <blockquote>
    <p>UriFormatException: Uri is longer than the maximum {0} characters.
    System.Uri.EscapeDataString (System.String stringToEscape)</p>
  </blockquote>
  
  <p>FYI image size is not big, it's only 23 kb and the type of the image is png.</p>
  
  <p>What is wrong with my code. Thanks for your help.</p>