I have checked across various platform for uploading ZIP file using Struts2.
I get some reference from http://struts.apache.org/docs/file-upload.html but not worth I know we can upload the multiple files using Struts 2 but I would like to upload it as zip folder.
Is it possible to upload the files using Struts2?
jsp page
<s:form action="doUpload" method="post" enctype="multipart/form-data">
<s:file name="upload" label="File"/>
<s:submit/>
</s:form>
action class
public class UploadAction extends ActionSupport {
private File[] upload;
private String contentType;
private String[] filename;
public File[] getFileUploads() {
return upload;
}
public void setFileUploads(File[] fileUploads) {
this.upload= fileUploads;
}
public String[] getUploadsFileNames()
{
return filename;
}
public void setUploadsFileName(String[] uploadFileNames)
{
this.filename= uploadFileNames;
}
public String execute() {
try{
String localPath = "C:\\tmp\\localDir";
for (int i = 0; i < upload.length; i++)
{
File fileToCreate = new File(downloadDir.getAbsolutePath(), voiceBasePromptsFileNames[i]);
FileUtils.copyFile(upload[i], fileToCreate);
}
}catch(Exception e){}
return SUCCESS;
}
}
sturts.xml
<action name="doUpload" class="com.example.UploadAction">
<param name="contentType">application/zip</param>
<param name="inputName">zipFileInputStream</param>
<param name="contentDisposition">attachment;filename="${fileName}"</param>
<param name="bufferSize">1024</param>
<param name="contentLength">${contentLength}</param>
<result type="json" />
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
by using this code I can only upload the single file at a time but when I tried for zip file I got null for contentType , filename. ..Added updated code which I tried now but still didnt get any luck.
EDIT
Sorry if my question is not clear to you...adding some more point and updated code which I just tried but not working.
I have multiple file to upload, so I make a zip of all files and want to load that zip file using struts2 in one shot.
As I mentioned above, filename or its contentType comes as Null.
So my question is, do I need to setcontentType somewhere in struts.xml or if you have any example which I can refer for uploading zip through struts2.