Hello All ! I use the Struts v.1.0.2
Unfortunatelly I can't realize file uploading. And the most confusing that I have 2 different errors on different files with the same code. Here's my form: <html:form action="/addImage.do" enctype="multipart/form-data" > <html:hidden property="pkPartner" /> <html:file property="imgFile" /> <br> <html:submit property="submit" value="Save" /> <html:reset/> </html:form> Here's form bean: ... public final class ImagesPartnerForm extends ActionForm { private String pkPartner = null; private FormFile imgFile = null; ... public FormFile getImgFile(){ return this.imgFile; } public void setImgFile( FormFile imgFile ){ this.imgFile = imgFile; } public void reset( ActionMapping mapping, HttpServletRequest request ){ pkPartner = (String)request.getAttribute( "pkPartner" ); imgFile = null; } ... Here's action that handles form data: public final class AddImage extends ActionExt { public ActionForward perform( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, String userName ) throws IOException, ServletException { String subpath = "/partner"; String targetDir = ResourceHandler.getProperty( "global", "pictures.dyn.abs-root" ) + subpath; String dbPath = ResourceHandler.getProperty( "global", "pictures.dyn.rel-root" ) + subpath; ImagesPartnerForm iform = (ImagesPartnerForm)form; FormFile ff = iform.getImgFile(); // String name = ff.getFileName(); String targetFile = targetDir + "/" + name; String dbFile = dbPath + "/" + name; // Save file to filesystem java.io.DataInputStream dis = new java.io.DataInputStream( ff.getInputStream() ); java.io.DataOutputStream dos = new java.io.DataOutputStream( new java.io.FileOutputStream( targetFile ) ); for( int i = 0; i < ff.getFileSize(); i++ ){ dos.writeByte( dis.readByte() ); } dos.flush(); dos.close(); dis.close(); return new ActionForward( "/jsp/partner/test.jsp" ); } } ERRORS: 0) short text file was uploaded without any corruption, but: 1) One jpeg file was uploaded, but had less size then source. 2) Other jpeg file uploading caused an exception: javax.servlet.ServletException: IOException while reading file element: Premature end of stream while reading multipart request at org.apache.struts.upload.MultipartIterator.getNextElement(MultipartIterator.java:222) at org.apache.struts.upload.DiskMultipartRequestHandler.handleRequest(DiskMultipartRequestHandler.java:76) at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:735) at org.apache.struts.action.ActionServlet.processPopulate(ActionServlet.java:2061) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1564) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:510) at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>