Stack Exchange
File Upload with RequestBuilder
I need to upload a file in GWT in the background, ie. not from a visual widget.
For this I've found the RequestBuilder class, but little documentation on how to use it for upload purposes.
The file content I need to upload is 100% plaintext.
My code so far looks like this:
final String filename = UUID.randomUUID().toString() + ".txt";

RequestBuilder rb = new RequestBuilder(RequestBuilder.POST, "http://localhost/upload");
rb.setRequestData(selected.getBody()); // getBody() is plain-text
rb.setHeader("Content-Type", "application/x-www-form-urlencodeddata");
rb.setCallback(new RequestCallback() {
    @Override
    public void onResponseReceived(Request request, Response response) {
        w.setUrl("http://localhost/magic.html?hide=status&open=" + filename);
        w.show();
        w.maximize();                            
    }

    @Override
    public void onError(Request request, Throwable exception) {
        exception.printStackTrace();
    }
});

// Checked Exceptions sucks *sigh*
try {
    rb.send();
}
catch (RequestException e) {
    e.printStackTrace();
}

I hope someone can give me some pointers towards solving this issue, thanks!

I think it's not possible to upload files to the server without user interaction using JavaScript only. I think it's blocked by the browser, because it would mean anybody could upload any file from your system when you visit a site, which would be a major security problem. I don't know why you would want to do this, but I guess you need to look at another approach to what you are trying to do.

This isn't a browser operation, it's a background HTTP request sent from a Jetty (Java EE Application Server).
Which is perfectly doable (Hence why RequestBuilder exists in the first place), except I don't know how to build the correct formattet request.

oke I'm lost now;-) The RequestBuilder I know is a GWT client side class that is compiled to JavaScript, that runs in the browser. So when you say upload do you mean send to the server from the browser or the otherway around, or the browser has nothing to do with it all? and with HTTP request sent from you mean from Jetty to the Browser or the otherway around?

It seems that you can upload files with gears, so in the worst case you could implement something like this with javascript: link text
