Results 1 to 4 of 4

Thread: fileupload help

  1. #1

    Default fileupload help

    I'm looking at the fileupload example and I'm having a little trouble figuring out how to process the file from within ProcessUploadAction.java. Can someone give me a brief example of how to get at the file from within ProcessUploadAction.java?

    Thanks for the pointers.

  2. #2
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    Since the ProcessUploadAction puts the FileUploadBean in REQUEST scope (the default), you would do something like this:

    Code:
    public Event processFile(RequestContext context) throws Exception {
       FileUploadBean fub=(FileUploadBean)context.getRequestScope().getAttribute("file");
       byte[] fileData=fub.getFile();
       ... //process file data
       return success();
    }
    You would then need to invoke this processFile() method from an action state, something like this:

    Code:
    <action-state id="processFile">
       <action bean="upload.process"/>
       <transition on="success" to="..."/>
    </action-state>

  3. #3

    Default

    That's exactly what I've done. The only problem is that fub ends up being null.

  4. #4

    Default

    This did the trick.

    Code:
    public Event processFile&#40;RequestContext context&#41; throws Exception &#123;
       bindAndValidate&#40;context&#41;;
       FileUploadBean fub=&#40;FileUploadBean&#41;context.getRequestScope&#40;&#41;.getAttribute&#40;"file"&#41;;
       byte&#91;&#93; fileData=fub.getFile&#40;&#41;;
       ... //process file data
       return success&#40;&#41;;
    &#125;

Similar Threads

  1. Commons FileUpload with Spring
    By spring04 in forum Architecture
    Replies: 1
    Last Post: Sep 10th, 2009, 02:24 AM
  2. Replies: 4
    Last Post: Feb 13th, 2007, 12:22 PM
  3. FileUpload
    By strbuf in forum Web
    Replies: 11
    Last Post: Oct 14th, 2005, 02:13 AM
  4. FileUpload question
    By getagrip in forum Web
    Replies: 2
    Last Post: Jul 29th, 2005, 01:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •