2

I'm implementing a little webserver in my Android application. Therefor I have a WebServer class and I'm handling requests of the client by an HttpRequestHandler. Everything works fine, I can access html files via the browser and so on. The only thing which won't work is to upload a multipart file to the server. For this purpose I have a litte html form with an input field for files. Then I sent the form to the server and want to save the file on the server. My HttpRequestHandlers look like the following:

public class UploadHandler implements HttpRequestHandler {
    private Context context = null;

    public IndexCommandHandler(Context context) {
        this.context = context;
    }

    @Override
    public void handle(HttpRequest request, HttpResponse response,
    HttpContext httpContext) throws HttpException, IOException {

        //HERE i want to save the multipart file

    }

    public Context getContext() {
    return context;
    }
}

So my problem is to parse the HttpRequest incoming from the client to a file. How can I do this with java?

Phil123
  • 87
  • 11

1 Answers1

0

For a discussion of parsing the request, see Create and parse multipart HTTP requests in Python

That's python specific but the concepts should still apply.

And for more information, see Multipart requests/responses java

Community
  • 1
  • 1
aeliusd
  • 469
  • 7
  • 18
  • Hey, thanks fpr your reply. This posts don't really solved my problem. I understand the basic conecpt of parsing the request so the example in Python isn't very helpful. The second post isn't really helpful too because FileUpload needs a servlet. I don't have one. Instead of that I need to parse the HttpRequest object and not the HttpServletRequest... Any other ideas? – Phil123 Feb 28 '13 at 11:13