1

I am trying to get file from multipart/form.For this I am using HttpRequestHandler

here is my class

public class ResponseHandler implements HttpRequestHandler {

@Override
public void handle(HttpRequest request, HttpResponse response,
        HttpContext httpContext) throws HttpException, IOException {
    InputStream is = ((HttpEntityEnclosingRequest) request)
            .getEntity().getContent();
    //how extract file here 
   //stream consist other form data 

}
public void saveImage(InputStream input,File file){
try {

        OutputStream output = null;
    try {
        output = new FileOutputStream(file);
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    try {
        try {
            final byte[] buffer = new byte[1024];
            int read;

            while ((read = input.read(buffer)) != -1)
                output.write(buffer, 0, read);

            output.flush();
        } finally {
            output.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
} finally {

   }
  }
}

Here is multipart/form

<form action="upload" method="post" enctype="multipart/form-data">
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>

I am able to get inputstream which contain file and form data.So question is how to extract file and other data from inputsream.

Here is file looks like if I am saving inputstream as it is:

------WebKitFormBoundaryzxxA1lnrlIK6B9ob Content-Disposition: form-data; name="fileToUpload"; filename="a.jpg" Content-Type: image/jpeg

ÿØÿàÿÀÿÀÿÀ 234gy 2ÿØÿàÿÀÿÀÿÀ 234gy 2ÿØÿàÿÀÿÀÿÀ 234gy 27ÿØÿàÿÀÿÀÿÀ 234gy 2ÿØÿàÿÀÿÀÿÀ 234gy 2ÿØÿàÿÀÿÀÿÀ 234gy 2..............................

0 Answers0