Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

form with attachment

Avatar

Level 4
hi all,

im rendering a form through a process(invoking the process through a servlet)... the form will allow the user to attach files. on click of submit button, it calls a servlet. the servlet should check if the form contanins any attachments...if yes it should save the attachments in DB, but when ever i check for attachments in the servlet(console) it says "empty".



and whn i try saving the form in a the local drive and open it, it says not of proper format.now whr is the issue in the form or the way i check for attachments
3 Replies

Avatar

Former Community Member
Ambika,



Yesterday I put together a servlet to accomplish a similar task. The following code snippet gets the submitted PDF from the HTTP request input stream, calls Forms ES to render the PDF, gets the attachments from the rendered PDF, and iterates over the attachments. I added comments in the while loop, below, to indicate possible actions.



...

Document formIn = new Document(req.getInputStream());



RenderOptionsSpec renderOptionsSpec = new RenderOptionsSpec();

renderOptionsSpec.setLocale("en_US");



FormsResult formOut = formsServiceClient.processFormSubmission(formIn,

"CONTENT_TYPE=application/pdf",

"",

renderOptionsSpec);



List fileAttachments = formOut.getAttachments();

Iterator iter = fileAttachments.iterator();

int i = 0 ;



while (iter.hasNext()) {

Document fileAttachment = (Document)iter.next();

// do DB processing or validate the attachments using...

// File myFile = new File("C:\\attachment" + i + ".pdf");

// fileAttachment.copyToFile(myFile);

i++ ;

}

...



Steve

Avatar

Level 4
hi walker,



the same thing i did, still nothing seems to work.It always prints in the console as "attachments empty." please help me out in resolving this issue.