I'm trying to upload data to CrowdFlower using their api, for which I'm writing JAVA wrapper. I'm using HttpClient Apache.
the cURL example CrowdFlower give is following: curl -T 'sampledata.xlsx' -H 'Content-Type: application/vnd.ms-excel' https://api.crowdflower.com/v1/jobs/upload.json?key={api_key}
here is my code:
public InputStream HTTPmethodPostUpload (String authKey, File file) throws ClientProtocolException, IOException{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("https://api.crowdflower.com/v1/jobs/upload.json?key="+authKey);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbody = new FileBody( file,"application/vnd.ms-excel");
mpEntity.addPart("sampledata.xlsx", cbody );
httpPost.setEntity(mpEntity);
HttpResponse response = httpclient.execute(httpPost);
HttpEntity entityResponse = response.getEntity();
return entityResponse.getContent(); }
Hower it returns me an error with the following message:
{Un-Acceptable format, Content-Type must be one of those listed in \"formats\" but you sent \"multipart/form-data; boundary=yTuwTm4hWmnasxIMB9dC-sxdELIGoNJVudjJdCz\"","formats":["application/vnd.oasis.opendocument.spreadsheet","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-excel","text/csv","text/plain"]}}
I don't know Apache HttpClient well so I don't understand where is the problem in my code.