I am getting a Server Error with the code 500 while trying to upload a json file to a server.The problem occurs because of the parameters. When I use a plain json string, without a multipart builder, then it works. Code I use is below
Many thanks in advance
public void uploadSegmentCustomerList(File jSonFile, String segmentId) throws IOException {
if(this.apiClient.getToken() == null){
apiClient.login();
}
MultipartEntityBuilder
builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
HttpPost uploadPost = new HttpPost(restConfig.getBaseUrl() + restConfig.getUploadUrl().replace("@segmentId@",segmentId));
uploadPost.setHeader("sessionToken", this.apiClient.getToken());
// This attaches the file to the POST:
File f = jSonFile;
builder.addBinaryBody("test" , new FileInputStream(f), ContentType.APPLICATION_JSON,f.getName() );
HttpEntity multipart = builder.build();
uploadPost.setEntity(multipart);
HttpResponse response = apiClient.uploadPost(uploadPost);
int responseCode = response.getStatusLine().getStatusCode();
log.info(String.valueOf(response)+ " "+ responseCode);
}