Sunday, 8 September 2013

upload file in jsf 2.2

upload file in jsf 2.2

Using my company's chosen cloud storage api and just starting out with JSF
2.2. Trying to build a simple image upload web app and it works when I run
locally using Eclipse.
Here's the code: .xhtml page
<h:form id="form" enctype="multipart/form-data" prependId="false">
Select id Photo: <h:inputFile id="file"
value="#{customerEntity.uploadedFile}"/>
<h:commandButton value="Query Cloud"
action="#{customerEntity.addActionController}"/>
</h:form>
customerEntity.java code:
private Part uploadedFile;
private String fileURI;
On local machine, code to extract file name from Part object uploadedFile
produces correct file locator (eg. c:\pictures\mypix.jpg) for local access
on my machine.
However, when I load into tomcat 7 running in a cloud vm, the application
fails with a FileNotFound in the 'try' block:
File source = new File(this.fileURI);
try {
cloud.upload(new FileInputStream(source), source.length());
My debug statements show it's using the file locator from my local pc
which clearly doesn't exist on the server. I can't figure out how to get
the local file data streamed to the code running on the server.
As a slight jsf newbie, I'm sure it's something obvious, but can't figure
it out or resolve via some of the other posts I've seen.
Any guidance would be greatly appreciated!

No comments:

Post a Comment