title: 415 Unsupported MediaType Error
body: <p>I am uploading a Photo to the server using HTTPS POST request. The request is Multipart and I am using this code to upload the pic.</p>
  
  <pre><code> public HttpResponse uploadPhoto(File imagePath) {
  
      try {
  
          HttpPost httppost = new HttpPost(
                  "https://wbapi.cloudapp.net:443/api/Submission/UploadCompetitionEntry?folderName=photos");
  
          MultipartEntity multipartEntity = new MultipartEntity(
                  HttpMultipartMode.BROWSER_COMPATIBLE);
  
          httppost.setHeader( "Content-Type", "multipart/form-data" );
          httppost.setHeader("Accept", "application/json");
          httppost.setHeader("Authorization", getAuth());
          multipartEntity.addPart("CompetitionID", new StringBody("84"));
          multipartEntity.addPart("UserId", new StringBody(""
                  + LoginActivity.id_user));
          multipartEntity.addPart("Title", new StringBody(""
                  + edit_title.getText().toString()));
          multipartEntity.addPart("Summary", new StringBody(""
                  + edit_description.getText().toString()));
          multipartEntity.addPart("photos", new FileBody(imagePath,"image/jpeg"));
          multipartEntity.addPart("MediaType", new StringBody("Photo"));
          multipartEntity.addPart("Visibility", new StringBody("Public"));
          multipartEntity.addPart("DateCreated", new StringBody(
                  "2013-01-04T10:07:46.9450000Z"));
          httppost.setEntity(multipartEntity);
          http = mHttpClient.execute(httppost);
  
      } catch (Exception e) {
          Log.v("Exception", "" + e.getMessage());
          e.printStackTrace();
      }
      return http;
  }
  </code></pre>
  
  <p>and my HTTPClient is this</p>
  
  <pre><code>mHttpClient = WinboutServerRequests.getHTTPClientObject();
  </code></pre>
  
  <p>This takes care of the HTTPS Certificate stuff with Helper classes.</p>
  
  <p>When I am doing the request, I am getting e.getMessage() as null and in StackTrace I am getting this</p>
  
  <p>I have to send these entities to the server</p>
  
  <p>Request to be sent </p>
  
  <h2>Request</h2>
  
  <blockquote>
    <p>curl -X POST "https://wbapi.cloudapp.net:443/api/Submission/UploadCompetitionEntry?folderName=photos" -F "Summary=My description" -F "CompetitionID=84" -F "Title=photo titile" -F "MediaType=Photo" -F "AuthorName=dog" -F "UserId=1251" -F "DateCreated=2013-01-04T10:07:46.9450000Z" -F "Visibility=Public" -F "photos=@/Users/akshayhegde/Library/Application Support/iPhone Simulator/5.1/Applications/D8A03B97-B7CC-4655-8987-8A54AE3E5FFC/Documents/UserData/competitionEntry/photoEntryHeaderImage.jpg;type=application/octet-stream"</p>
  </blockquote>
  
  <p>Answer :</p>
  
  <p>There was this Authorisation which has to be added to the header which was missing.I added it and Now I am not getting CientProtocolException.</p>
  
  <p>Added Utility Function to get the MIME Type of the file</p>
  
  <pre><code>public static String getMimeType(String url)
  {
      String type = null;
      String extension = MimeTypeMap.getFileExtensionFromUrl(url);
      if (extension != null) {
          MimeTypeMap mime = MimeTypeMap.getSingleton();
          type = mime.getMimeTypeFromExtension(extension);
      }
      return type;
  }
  </code></pre>
  
  <p>But I am getting 415 Unsupported Media Type error, What we have to set the ContentType for uploading Pictures ?</p>
  
  <p><strong>Sample request to be sent :</strong></p>
  
  <p>Content-Disposition: form-data; name="CompetitionID"</p>
  
  <h2>3</h2>
  
  <p>Content-Disposition: form-data; name="UserId"</p>
  
  <h2>1</h2>
  
  <p>Content-Disposition: form-data; name="Title"</p>
  
  <h2>caesar and hiro</h2>
  
  <p>Content-Disposition: form-data; name="Summary"</p>
  
  <h2>window</h2>
  
  <p>Content-Disposition: form-data; name="MediaType"</p>
  
  <h2>Video</h2>
  
  <p>Content-Disposition: form-data; name="DateCreated"</p>
  
  <h2>2012-06-07T02:17:57.09</h2>
  
  <p>Content-Disposition: form-data; name="Visibility"</p>
  
  <h2>Public/Private</h2>
  
  <p>Content-Disposition: form-data; name="photos"; filename=IMG_9322.JPG</p>
  
  <h2>Content-Type:application/octet-stream</h2>
  
  <p>Content-Disposition: form-data; name="videos"; filename=sample.avi</p>
  
  <h2>Content-Type:application/octet-stream</h2>
  
  <p>Content-Disposition: form-data; name="music"; filename=sample.avi</p>
  
  <h2>Content-Type:application/octet-stream</h2>
  
  <p>Content-Disposition: form-data; name="writings"; filename=sample.txt
  Content-Type:application/octet-stream</p>