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 23, 2011, 7:17 AM
6 Posts

Get filepath of uploaded file

  • Category: Other
  • Platform: All
  • Release: 8.5.2
  • Role: Developer
  • Tags: file upload,file path
  • Replies: 14
 
Hi All,

On my XPage I have a field asking the user to put in the path of a required file. This file is not attached to the document at all.
 
To make things simpler for the end user I put an upload control instead of a normal edit box. The idea was that the user can browse and select the file after which we can extract the full file-path e.g. C:\Test\Book1.xlsx. But the problem is that i cannot get the path of the file from the file upload control.
 
I am using the getComponent method but it does not help at all. Are there any other ways available to do this?

Regards,
Sayan
 
 
Mar 23, 2011, 8:31 PM
261 Posts
Re: Get filepath of uploaded file
Hi Sayan,
 
Using the technique I described here

http://www.bleedyellow.com/blogs/m.leusink/entry/processing_files_uploaded_to_an_xpage?lang=en
 
you can get a handle on the uploaded file. You have to check if one of the properties of the uploaded file contains the full path, although I'm not sure that the clientside path is sent to the server at all. From what I remember, as a security measure, browsers only send the file name, not the path.
 
Mark
Mar 24, 2011, 6:45 AM
6 Posts
Re: Get filepath of uploaded file
Hi Mark,
 
Thanks a lot but I think I am a bit confused. Does your code give me data of a file that is already uploaded or to be uploaded?
 
Thanks,
Sayan

Mar 24, 2011, 8:11 AM
261 Posts
Re: Get filepath of uploaded file
Hi Sayan,
 
It gives you a handle to a file that was just uploaded to the server. You can use the code in (for instance) the beforeRenderResponse event of an XPage to process the file.
 
The handle is actual a reference to a temporary file in the <data dir>/xspupload folder of your server.

Mark
Mar 24, 2011, 10:52 PM
4 Posts
Re: Get filepath of uploaded file
Hi Mark,
 
I am also having problems getting a handle on the just uploaded file.

I've read you blog posting and I'm using the code you offered in the beforeRenderedResponse event
 I'm using an xp upload control that renames the file to "image.jpg" and it's bound to an RTF.
 
when I submit the xpage, I get the following error from the beforeRenderedResponse:
 
"HTTP JVM: com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript action expression"
 
Through print statements, I've tracked it down to the "var tempFile:java.io.File = fileData.getServerFile()" line.
 
 The Notes document gets created with the attachment just fine.  But I want to get a handle on the image.jpg to create a thumbnail.
 
any help you can provide would be very much appreciated.

Regards,
 
Dan
Mar 25, 2011, 12:19 PM
261 Posts
Re: Get filepath of uploaded file
Hi Dan,
 
Have you tried to disable the file renaming option? It might be that that's causing the problem.

Mark
Mar 25, 2011, 5:28 PM
4 Posts
Re: Get filepath of uploaded file
Mark,
 
Per your suggestion, I disable the file renaming option, but it did not affect my issue.  I've left it disable and ran a few more tests.
It appears that the fileData variable is not getting set

From the Console:
HTTP JVM: **** in beforeRenderResponse
HTTP JVM: **** Code Line 1:  var con = facesContext.getExternalContext
HTTP JVM: **** con is NOT null

HTTP JVM: **** Code Line 2: var request:com.sun.faces.context.MyHttpServletRequestWrapper = con.getRequest
HTTP JVM: **** request is NOT null

HTTP JVM: **** Code Line 3: var map:java.util.Map = request.getParameterMap
HTTP JVM: **** map is NOT null

HTTP JVM: **** Code Line 4: var fileDataName = "file"
HTTP JVM: **** fileDataName NOT null
HTTP JVM: **** fileDataName = file


HTTP JVM: **** Code Line  5:  var fileData:com.ibm.xsp.http.UploadedFile = map.get( fileDataName )
HTTP JVM: **** fileData IS null

HTTP JVM: **** Code Line  6: var tempFile:java.io.File = fileData.getServerFile
HTTP JVM: com.ibm.xsp.exception.EvaluationExceptionEx: Error while executing JavaScript action expression

Thank you for you time.
 
Regards,

Dan
dlarson@synerjetic.com
Mar 25, 2011, 7:56 PM
39 Posts
Re: Get filepath of uploaded file
If you just need the path in the file upload control, is there any reason why you aren't just doing it on the client side and then putting into a hidden text field so the server side can access it?
 
 
Mar 26, 2011, 7:43 AM
261 Posts
Re: Get filepath of uploaded file
The sample I've described in my blog post can be used to create an XPage that can handle files that are (HTTP) POSTed to it.

To post a file to such an XPage you'd need to create (for instance) a HTML page, containing a file upload, with the form method set to POST and the action to the location of the XPage.
 
It's probably possible to change the code so it can handle a file upload contained on it, but I haven't tested that. The could would probably have to be moved to the querySaveDocument event.
 
Mark
Sep 20, 2011, 10:59 PM
7 Posts
Re: Get filepath of uploaded file
 Hi Mark,
 
I need to resize a profile image once uploaded so using your code I'm trying to get a handle on the just uploaded file but no luck, 
 
Could you give me some hints? 
 
I also tried getting the already attached file from the RichText item but no luck converting it to a Java file 
 
Thanks in advance, 
Daniel 
Sep 21, 2011, 7:29 AM
261 Posts
Re: Get filepath of uploaded file
Daniel,
 
Download Bildr from OpenNTF and have a look at the source code. It contains code to do exactly what you want in the user profile section (resizing an uploaded profile image).
 
The custom control in which the resize function is called is cc_profile_picture (I think...). You'll also need a Java class to do the actual resizing: the class can be found in Bildr, but you need to use the package explorer to view it.
 
Mark
Oct 25, 2011, 8:38 PM
7 Posts
Re: Get filepath of uploaded file
 Hey Mark,
 
Thanks for your response, it's been a while and now I'm back trying to work out this. 
 
I had a look at Bildr and the code in the profile, that works ok although it would be great to be able to use the crop method you have in the albums when you upload multiple images. 
 
Am I missing something? I could not found a way to use the same method to crop. I managed to scale the image to the proper height and width but I would like to be able to resize whatever the user uploads to a square image and for that I need to crop the image so it does not get deformed. 
 
I'm also trying to avoid saving the image once upload in case the user decides to discard the changes but it looks a bit tricky. 
 
I really appreciate your help. 
 
Thanks in advance, 
Daniel 
Oct 30, 2011, 8:27 AM
261 Posts
Re: Get filepath of uploaded file
Daniel,
 
You might want to take a look at the ScaledImage class (in the "code" section). It contains the code to resize an image.
 
If you search for the "targetCrop" variable, you'll see that images will automatically be cropped if:
  • The target format is square (width = height).
  • The resize mode is 1 (max values for x and y) - can be set using the setResizedMode function.
Have a look at the xpUploads library to see how uploaded images are resized.
 
Mark
 
Jan 2, 2012, 6:40 PM
7 Posts
Re: Get filepath of uploaded file
 Hi Mark,
 
Sorry to bother you again with this but I'm know getting an Invalid file extension error when using Bildr in firefox, as far as I could google this error started appearing on Firefox 7.01 or later, I'm using 9 btw and seems to be related to the plupload library. 
 
Not sure what files need to be replaced to update Bildr to the latest plupload release to try to fix this. 
 
Could you please help me with this? 
 
Thanks in advance, 
Daniel 
Jan 3, 2012, 8:34 PM
261 Posts
Re: Get filepath of uploaded file
Daniel,
 
You're right: it is a plupload issue. I already fixed it in a new release of Bildr by updating the version of plupload to 1.5.1.1. Unfortunately that version of Bildr hasn't been release yet, but I can tell you what you need to change:
 
- 3 files updated using the plupload 1.5.1.1 download:
 
plupload.full.js (removed plupload.full-min.js)
plupload.flash.swf
plupload.silverlight.xap
   
- ccUploadImages (custom control), changed the line:

<script type="text/javascript" src="plupload.full.min.js"></script>

to

<script type="text/javascript" src="plupload.full.js"></script>

- xpUploads (script library), changed the beforeRenderResponse function in aUpload and aUploadA:

var strFileName = context.getUrlParameter("name");   
 var dataName = context.getUrlParameter("dataName");   
if (dataName == null || dataName == "") {   

                   
to
                   
var strFileName = param.get("name");   
var dataName = param.get("dataName");       
if (dataName == "") {
 
Good luck!

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