Is it possible to add the file extension into the HTTP header?
I have developed a program for sending a file using an API call. The file will not be restricted to .doc or .pdf, it can be with .exe or .zip extension as well.
The file is successfully uploaded to the server but the file extension seems not correct, it's showing the file type as data, while I'm expecting another file type.
Here down the sample code sources for the upload part:
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://ServerName:Port/Anything/data"); //remote API URL
String filepath = "C://User//test//";
String file1 = filepath.concat(file);
System.out.println("Sending the file");
FileBody bin = new FileBody(new File(file1)); // take the file from directory
HttpEntity reqEntity = MultipartEntityBuilder.create()
.addPart("display_name", (ContentBody) bin)
.build();
post.addHeader("filename", file1);
post.setEntity(reqEntity); // send via post method
Will the FileBody read the file extension as well?