1

I'm trying to develop an application with file upload using Struts 2.

How can we upload files from different location (select one file from one location and again click on file input and select file from another location)?

When this is done , only last selected file is obtained from file tag.

I was able to upload multiple files from same location using multiple property of file tag. How to achieve uploading files from different locations?

Roman C
  • 49,761
  • 33
  • 66
  • 176
mary r
  • 93
  • 1
  • 2
  • 8

1 Answers1

0

You can achieve if you use multiple input controls bound to the properties of the action.

<s:form action="doUpload" method="post" enctype="multipart/form-data">
    <s:file name="upload" label="File1"/>
    <s:file name="upload" label="File2"/>
    <s:submit/>
</s:form>

If you are using HTML5 you can add dynamic attribute to Struts <s:file> tag multiple

<s:form action="doUpload" method="post" enctype="multipart/form-data">
    <s:file name="upload" multiple="multiple" />
    <s:submit/>
</s:form>

If you want to prepend the location to the file input control see Remember and Repopulate File Input

Related to HTML5 answer

current/future/HTML5-compliant browsers will always pre-pend the string: c:\fakepath\ to the filename when getting the file-input's value On top of that, they will only return the first filename (from a list of selected files) should the file-input accept multiple files and the user has selected multiple files.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • Thanks for your response. But my requirement is one input file. Also its not just two upload, it should be any number of times. Is there any other option? – mary r Feb 18 '16 at 08:25
  • it's one upload but two different locations. You can add any number of input tags. – Roman C Feb 18 '16 at 08:32