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!

SpecTrum
  • 67
  • 1
  • 6
  • Why doesn't it work with other files? What are the symptoms? Why is this tagged android? – ddmps Mar 22 '13 at 06: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 http://stackoverflow.com/a/2937140/1690982 – ddmps Mar 22 '13 at 07:03

1 Answers1

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).

FrancescoAzzola
  • 2,666
  • 2
  • 15
  • 22