Announcement Announcement Module
Collapse
No announcement yet.
fileupload help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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>

    Comment


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

      Comment


      • #4
        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;

        Comment

        Working...
        X