These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

File Upload - Browse functionality in Adobe

Pallavi_Gondkar
Registered: Oct 2 2008
Posts: 22

I am facing a problem in Adobe form; I have 2 buttons BROWSE1 and BROWSE2 on Adobe Form and two Text fields TEXT1 and TEXT2, on clicking of either of the buttons a popup appears on the asking the User to select the file that has to be uploaded. After I have selected the File in TEXT1 after clicking BROWSE1, I can see the file name in TEXT1.
When I click on the BROWSE2 the popup appears asking the user the to select the file to be uploaded, however if I cancel the popup at this point, ideally I shouldn’t see any file name in TEXT2, but the last file name which was uploaded through BROWSE1 in TEXT1 is getting copied in TEXT2. Whenever the cancel button on either of the BROWSE buttons is clicked the Last file which was selected gets populated in the either of the TEXT fields. I have tried number of things using the JAVA script but this doesn’t seem to be working properly. Since I am not a JAVA programmer please let me know if there is possible solution to above explained problem, I am providing the code below which I have used for your convenience.

BROWSE1:

var sFile = null;
event.target.importDataObject(sFile);

var oFile = null;
oFile = event.target.getDataObject(sFile);
this.parent.parent.Sub_4.FILE_PATH_PID.rawValue = oFile.path;

var pFile = event.target.getDataObjectContents(sFile);
var cFile = util.stringFromStream(pFile, "utf-8");

ADOBE_DATA.Main_Subform.Main_Form.Sub_4.FILE_CONTENT_1 = cFile;

BROWSE2:

var xFile = null;
event.target.importDataObject(xFile);

var gFile = null;
gFile = event.target.getDataObject(xFile);
this.parent.parent.Sub_4.FILE_PATH_WBS.rawValue = gFile.path;

var aFile = event.target.getDataObjectContents(xFile);
var mFile = util.stringFromStream(aFile, "utf-8");

ADOBE_DATA.Main_Subform.Main_Form.Sub_4.FILE_CONTENT_2.rawValue = mFile;

My Product Information:
Acrobat Standard 9.0, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
So, you are doing this in LiveCycle?? Are there any Reader Rights applied to this form?? These are very important data points for answering your question.

First, the "importDataObject()" function returns false if the user hits "Cancel". The code should switch off of this return value. The fact that it doesn't means that an exception is going to be caused down the line, if there are no other imported files. The code needs to test the return.

Next, you are naming the imported file "null" on both buttons. So, the JS code can't distinguish between files that were imported by the different buttons. So if you import a file with button 1, then cancel the button 2 import, the code grabs the data from the first import, because they have the same name.


Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Pallavi_Gondkar
Registered: Oct 2 2008
Posts: 22
Hi Thomp,

Thanks for the reply. I have one more question.

oFile = event.target.getDataObject(sFile);
this.parent.parent.Sub_4.FILE_PATH_PID.rawValue = oFile.path;

This code returns device independant path of the file. My requirement is to get full file path. Is there any java script method which will give me full file path.

Please give me the code here itself as I cant access the site mentioned above.

Pallavi
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
I don't know of a specific JavaScript fucntion for converting DI paths into Platform paths, but you could write your own. Here's some code for converting to a Window path style.

if(app.platform == "WIN"){var platPath = this.path.replace(/^\/(\w)\//,"$1:\\").replace(/\//g,"\\");}

This is a simple conversion that works for regular and mapped drives. It doesn't properly convert file paths for network drives.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/]http://www.adobe.com/devnet/acrobat/[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script