This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Mar 4, 2011, 5:36 PM
2 Posts

file Upload and Java

  • Category: Server Side JavaScript
  • Platform: All
  • Release: 8.5.2
  • Role: Developer
  • Tags:
  • Replies: 2
Hello,
 
I've a problem with  a file upload that I don't know how to solve it, I'll explain:
I've a file uploader wich will upload csv files.
My goal is to get the attachment to Java, create the documents I need with the data on it and don't save the uploaded file.
I can't get to pass the uploaded file(stream) to java so I need help...
 
Regards
Mar 4, 2011, 6:03 PM
39 Posts
Re: file Upload and Java
I had a similar problem a while back and got a handle on the UploadedFile Object by doing this:
 
    public void uploadFile(String serverid) {
        try {          
                String clientid = (String)FacesContext.getCurrentInstance().getApplication().getVariableResolver().resolveVariable(FacesContext.getCurrentInstance(), "#{id:"+serverid+"}");
                HttpServletRequest hsr = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
                Map map = hsr.getParameterMap();
                UploadedFile uf = ((UploadedFile)map.get(clientid));
                File fi = uf.getServerFile();
                // Do whatever you want with the file

            }
               catch (Exception e) {
                   System.out.println(e);
               }
        }
Oct 15, 2011, 8:01 PM
135 Posts
Re: file Upload and Java
Here is the SSJS code in XPage's beforeRenderResponse event: 
 

// See if we got an uploaded file, exit if not. "fuImport" is the ID of the File Upload Control.

var uploaded_file:com.ibm.xsp.http.UploadedFile = facesContext.getExternalContext().getRequest().getParameterMap().get(getClientId("fuImport"));

if (uploaded_file==null) return;

// Get the csv file

var file:java.io.File = uploaded_file.getServerFile();

 
It is based on this sample:
 

This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal