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

How to upload Multiple Files

Chandran
Registered: Mar 12 2008
Posts: 58
Answered

Hi All,

Kindly let me know how to upload multiple files in to Adobe form using Java Script.
Right now i am using the below code for uploading the files. I tried few things and finally what happens is that whatever the file which is uploaded finally was overwritten with previously uploaded files.

i am having the requirement to display the file names in the table.

var rowIndex = this.parent.index;

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

var oFile = null;
oFile = event.target.getDataObject(sFile);

xfa.resolveNode("MainForm.Subform.Table1.Row1["+rowIndex+"].Cell2").rawValue = oFile.path;

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

Kindly help us............

Thanks & Regards,
Chandran S

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You are importing the file attachments with a "null" name. You need to provide individual names for each imported item.

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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

Chandran
Registered: Mar 12 2008
Posts: 58
Hi thomp,

Thank you very much, i added the file name its working fine.
Kindly let me know how to delete the uploaded attachment through Javascript.

Thanks & Regards,
Chandran S
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Use the "doc.removeDataObject()" function.

The Acrobat JavScript Reference is your best friend.
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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

Chandran
Registered: Mar 12 2008
Posts: 58
Hi Thomp,

Thanks for the help, we are able to remove the attachments,

We need one more help to get in to the final step.
Openning the attached documents in adobe using Java Script
we are using the below code for this operation form the link

http://www.verydoc.com/documents/acrojsguide/pg_0131.htm

Opening and Saving AttachmentsYou may use Acrobat JavaScript to open any attachment. The general-purpose way to dothis is to invoke thedocobject’sgetDataObjectContentsmethod. The followingcode opens an attachment and displays its contents in the console:

var oFile = this.getDataObjectContents("MyAttachment");
var cFile = util.stringFromStream(oFile);
console.println(cFile);

Kindly help us

Thanks & Regards,
Chandran S
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
What do you mean by open? Do you want to display an attached PDF? or do you want to parse the byte level contents of the file?

The "doc.getDataObjectContents()" function returns the binary contents of the attached file. To display the file, use an ordinary "Go to page in Document" action on a line or button.

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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

Chandran
Registered: Mar 12 2008
Posts: 58
Hi Thomp,

Yes I just want to display the attachment (any type of attachments).

Thanks & Regards,
Chandran S
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Then use a link or a Mouse Up trigger on a button. Select the "Go to a Page View" action. Then use the mouse to open the attached PDF, before clicking on the "Set Link" button.

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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

Chandran
Registered: Mar 12 2008
Posts: 58
Hi Thomp,

Please, Can you eloborate in detail. How to handle that.
(The attachment mey be Excel, pdf,word etc)

Thanks & Regards,
Chandran S
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Oh, Using a link or button only works if the embedded file is a PDF. You can open something like an Excel file (i.e. a well know file type) with the doc.exportDataObject() function, when the "nLaunch" argument is set to 2.

For Example:
this.exportDataObject({cName:"Untitled Object 2", nLaunch:2});

Acrobat writes the file out to a temp folder and then asks the user if they want to allow the file to launch. This is a security feature. The embedded names are also unfortunate. Acrobat automatically uses the "Untitled Object" text. If you want better names you have to use JavaScript to do the file embedding.

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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

Chandran
Registered: Mar 12 2008
Posts: 58
Hi Thomp,

I used your code ( this.exportDataObject({cName:"Untitled Object 2", nLaunch:2}); )
inside a button click event, replacing the cName value with filename which is used at the time of embedding the attachments intothe PDF. i deployed my form and clicked on the button noting get executed.

Kindly Help Us

Thanks & Regards,
Chandran S
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The embedded name of a file is a completely different thing from the "File Name". As stated in the previous post. Acrobat automatically names embedded files, using "Untitled Object" as the base. If you have only one embedded file you can find out it's name with this code:

this.dataObjects[0].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/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

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

Chandran
Registered: Mar 12 2008
Posts: 58
Hi Thomp,

Great, Thanks a lot, its working now, i can screw it further.
Thank you very much for your patient response.

Thanks & Regards,
Chandran S