This content has been marked as final.
Show 4 replies
-
1. Re: upload file into web directory
cripto Sep 5, 2008 9:42 PM (in response to alejandropv)Excuse me, could perform what you
Wait?
If so, you could put your SOLUTION, PLEASE?
Is that I am having the same problemThank you
-
2. Re: upload file into web directory
michaelcourcy Sep 6, 2008 10:10 PM (in response to alejandropv)This work for me
@Name("uploadHandler") @Scope(ScopeType.EVENT) public class UploadHandler { @In(value="#{facesContext}") FacesContext facesContext; @Logger private Log log; private byte[] file; public void handleUpload() throws IOException{ String path = ((ServletContext) facesContext.getExternalContext().getContext()).getRealPath("/my/files/dir"); File f = new File(path,"myFile.txt"); log.info(f); FileOutputStream fo = new FileOutputStream(f); fo.write(file); fo.flush(); fo.close(); } public byte[] getFile() { return file; } public void setFile(byte[] file) { this.file = file; } }
and the form
<h:form id="fooForm" enctype="multipart/form-data"> <s:fileUpload id="file" data="#{uploadHandler.file}" accept="image/jpg" /> <h:commandButton id="upload" value="Upload !!" action="#{uploadHandler.handleUpload}"/> </h:form>
But I don't recommand to use the ....getRealPath(
/my/files/dir
);.... instead use a path that you configure in seam.properties. -
-
4. Re: upload file into web directory
nicolettait Jul 11, 2011 4:59 AM (in response to alejandropv)Hi! I've tried the code suggested by Michael, same .java, same .xhtml, adding to the components.xml the following configuration
<web:multipart-filter create-temp-files="true" max-request-size="1000000" url-pattern="*.seam"/>
The file it's always uploaded correctly, but it throws a null pointer exception on the line
fo.write(file);Maybe it'a a matter of file system permission, but I haven't found a good solution to this problem, has anyone experienced the same problem?