PLEASE, HELP !!! upload problem
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]
RE: PLEASE, HELP !!! upload problem
hi all, i want to use struts in my applications for the devolpment of a project on bea weblogic server. please suggest me what to download and what setting i have to do in the my server settings Thanks Regards Ajay -Original Message- From: Serge A. Redchuk [mailto:[EMAIL PROTECTED]] Sent: Friday, February 22, 2002 1:48 PM To: [EMAIL PROTECTED] Subject: PLEASE, HELP !!! upload problem 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(DiskMulti partRequestHandler.java:76) at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:735) at org.apache.struts.action.ActionServlet.processPopulate(ActionServlet.java:20 61) 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] INTIQUA International Intelligent Solutions, Quality Execution Note: The information and data contained in this message (and attachments) may be privileged and confidential and protected from disclosure to any party or parties apart from the intended recipient. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer.
PLEASE, HELP !!! upload problem
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]
Re: PLEASE, HELP !!! upload problem
try increasing buffer on your jsp page %@ page buffer=1000kb / From: Serge A. Redchuk [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: PLEASE, HELP !!! upload problem Date: Fri, 22 Feb 2002 10:17:54 +0200 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] _ Join the worlds largest e-mail service with MSN Hotmail. http://www.hotmail.com -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
PLEASE, HELP !!! upload problem
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]
PLEASE, HELP !!! upload problem
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]
Re: PLEASE, HELP !!! upload problem
I uploaded graphics just fine just now. My code is slightly different than yours. I simply call the getFileData() method of FormFile to return the data, and write it all out at once. Then flush the buffer and close the file. Try something along the lines of: FormFile ff = ... get the FormFile field FileOutputStream fos = new FileOutputStream(/some/path/ + ff.getFileName()); fos.write(ff.getFileData()); fos.flush(); fos.close(); If you still have problems let us know. I have to warn you, however, that people don't seem to care about file uploads. I asked for help and never got it. Of course my mistakes were because I was new, and a small amount of experimentation got me where I needed to go, but it's still annoying to be totally ignored. Hope that helps! Let us know if it does not. Eddie - Original Message - From: Serge A. Redchuk [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, February 22, 2002 2:17 AM Subject: PLEASE, HELP !!! upload problem 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(DiskMulti partRequestHandler.java:76) at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:735) at org.apache.struts.action.ActionServlet.processPopulate(ActionServlet.java:20 61) 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] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]