0

I would like to know if is possible get the image via POST method with a HTTP server implemented in Java (With a simple input file form). I already implemented the Java server but I can only get text files via POST method it's because that the my application only copies the file content to another empty file creating the same file with the same characteristics. This does not work with image file or other files, this can only work with text file.

Anyone know how to implement it with images? Some coordinates would be of great help! Thanks in advance!

2
  • Why doesn't it work with other files? What are the symptoms? Why is this tagged android? Commented Mar 22, 2013 at 6:59
  • Is it tagged android because you're having a problem sending the data from an android app? The question is kind of unclear. Anyways, if it is check out stackoverflow.com/a/2937140/1690982 Commented Mar 22, 2013 at 7:03

1 Answer 1

1

As far as i know you should create something like it:

Server-side: If you use a servlet that receive data in post you have to get the outputStream from the response. Once you have it it is done because you write the data image on the stream. For example let's suppose your image is a file stored in the server you could do:

    response.setContentLength((int) fileSize);
    byte b[] = new byte[1024];

while ( fOutStream.read(b) != -1)
   response.getOutputStream().write(b);

   fOutStream.close() ; 

Where the fOutStream is the source stream (your image).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.