Pregunta

I have one requirement in my app say. I need to get the content of the file from disk and send it to some external URL and want to confirm the external URL got the content or not.

In my Application user can select one document and say viewer so that it will display selected file converted version. For the conversion of that file I need to send selected file to .Net application URL which will convert it in the 3D modeling file and display response on my browser.

Here is my code which I am using to send the file first.

try{
  File f = new File("/home/Desktop/rename.txt");
  PostMethod filePost = new PostMethod("external URL");
  Part[] parts = { new FilePart("file", f) };
  filePost.setRequestEntity(new MultipartRequestEntity(parts,
  filePost.getParams()));
  HttpClient client = new HttpClient();
  int status = client.executeMethod(filePost);
  System.out.println(status);
}catch(Exception e){
  e.printStackTrace();
}
¿Fue útil?

Solución

If I understand it right, the server on the external URL should convert the file you're uploading and return a converted version of the file. Thus, this converted version would be contained in the body of the server's response. So it's not enough to simply check the status but you have to get the response itself.

You can achieve that by using client.execute() instead of client.executeMethod() about like so:

HttpResponse response = client.execute(filePost);
InputStream is = response.getEntity().getContent();

Now you can read the converted data from the input stream is and proceed as you like (e.g. save to disk etc.)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top