0

I have a fileUploader widget that I'm using to select an xml file. I then have a button that calls my handler in the viewImpl class when the user submits the selected file. If I understand things correctly, from there I do a submit from the formPanel and the file is on the server.

@UiHandler("calculateComplexityButton")
    void onClickCalculateComplexity(ClickEvent e){
        formPanel.submit();
        //How do I get the inputStream back to here????
        presenter.getTask(inputStream);
    }

My problem is how do I get the inputStream off the server? I tried using an RPC call for all this, but when I try to get the inputStream I'm not pulling anything off the server. I tried:

inputStream = request.getInputStream();

but it appears to be empty. Any ideas on this?

I dropped the RPC code and used a simple HTTPRequest I found here. That gets me to the servlet, but the request doesn't have the file stream. When I reach this line in the code:

FileItemIterator iter = upload.getItemIterator(request); //Nothing is here in iter.
Community
  • 1
  • 1
James Drinkard
  • 15,342
  • 16
  • 114
  • 137
  • are you using Java on server side? – Henrique Miranda Dec 07 '11 at 17:09
  • Yes. I thought I had this figured out. I'm using an RPC service call to a serviceImplServlet that extends RemoteServiceServlet. I get to the servlet fine, but getting the inputStream that the fileUploader created and put on the server doesn't seem to work and I'm not sure how to do this? – James Drinkard Dec 07 '11 at 17:23

1 Answers1

1

You can not make an upload via RPC, thats why you have to submit your form to a servlet.

final FormPanel form = new FormPanel();
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
form.setAction("/upload");

So, when you do form.submit() it will send your file to the Action(Servlet). In the server side you can use the lib form apache (commons-fileupload). You have many different way to get your file, you can save on disk, read on memory....

Henrique Miranda
  • 984
  • 1
  • 9
  • 28
  • I'm not using RPC for the file upload, I'm using RPC to get to a RemoteServiceServlet implementation and from there I'm trying to get the file stream back. I didn't set the form action though, so I have to use an HTTPServlet to pull the inputStream back off the server? – James Drinkard Dec 07 '11 at 17:58
  • Okay, but I'm not seeing anything in the request. Does the uploader widget set an attribute for the uploaded file? – James Drinkard Dec 07 '11 at 18:43
  • 1
    You must set `fileUpload.setName("myFile")`. Then when you submit the form it will add the myFile attribute. Also your fileUpload must be in the form like `formPanel.add(fileUpload)`, but I think you know that. Are you using firebug to see the request? – Henrique Miranda Dec 07 '11 at 18:51
  • That is what I was missing. I'm using Firebug, but the Net panel wasn't enabled. Now the code is working! Many thanks for the help! – James Drinkard Dec 07 '11 at 18:59