Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Retrieving File Attachments from adobe adaptive form

Avatar

Avatar
Validate 1
Level 1
mohamedn4455443
Level 1

Likes

0 likes

Total Posts

46 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Ignite 1
Give Back 3
Give Back
Affirm 1
View profile

Avatar
Validate 1
Level 1
mohamedn4455443
Level 1

Likes

0 likes

Total Posts

46 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Ignite 1
Give Back 3
Give Back
Affirm 1
View profile
mohamedn4455443
Level 1

03-05-2020

How to get File Attachments from adobe adaptive form to maven project?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Ignite 5
Employee
workflowuser
Employee

Likes

133 likes

Total Posts

443 posts

Correct Reply

70 solutions
Top badges earned
Ignite 5
Ignite 3
Ignite 1
Give Back 50
Give Back 5
View profile

Avatar
Ignite 5
Employee
workflowuser
Employee

Likes

133 likes

Total Posts

443 posts

Correct Reply

70 solutions
Top badges earned
Ignite 5
Ignite 3
Ignite 1
Give Back 50
Give Back 5
View profile
workflowuser
Employee

28-06-2020

This is an easier and recommended way to get hold of the AF attachments on form submission. Please follow the steps mentioned below

Down load the sample bundle and deploy it using web console in AEM

Import the Sample Package using package manager. This package has the  custom submit 

Import the Sample Adaptive Form using the package manager. This adaptive form is configured to submit to the custom submit handler called

"handleafsubmission"

Preview the Test Attachments form . Add a couple of attachments and submit

The attachments will be written to the folder of your AEM installation

I have deleted my earlier response since this is the recommended approach

Answers (6)

Answers (6)

Avatar

Avatar
Ignite 5
Employee
workflowuser
Employee

Likes

133 likes

Total Posts

443 posts

Correct Reply

70 solutions
Top badges earned
Ignite 5
Ignite 3
Ignite 1
Give Back 50
Give Back 5
View profile

Avatar
Ignite 5
Employee
workflowuser
Employee

Likes

133 likes

Total Posts

443 posts

Correct Reply

70 solutions
Top badges earned
Ignite 5
Ignite 3
Ignite 1
Give Back 50
Give Back 5
View profile
workflowuser
Employee

28-06-2020

package com.aemforms.handleafsubmission.core.servlets;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

import javax.servlet.Servlet;
import javax.servlet.ServletException;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.request.RequestParameter;
import org.apache.sling.api.request.RequestParameterMap;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adobe.aemfd.docmanager.Document;
@component(service = {
Servlet.class
}, property = {
"sling.servlet.methods=get",
"sling.servlet.methods=post",
"sling.servlet.paths=/bin/getsubmitteddata"
})

public class GetSubmittedData extends SlingAllMethodsServlet {


Logger logger = LoggerFactory.getLogger(GetSubmittedData.class);


private static final long serialVersionUID = -8884406699033680092 L;
protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException {
// get the submitted form data
String submittedData = request.getParameter("jcr:data");
logger.debug(submittedData);
RequestParameterMap requestParameterMap = request.getRequestParameterMap();
for (Map.Entry < String, RequestParameter[] > pairs: requestParameterMap.entrySet()) {
final org.apache.sling.api.request.RequestParameter[] pArr = pairs.getValue();
final org.apache.sling.api.request.RequestParameter param = pArr[0];
if (!param.isFormField()) {
try {
logger.debug("Got attachment!!!!" + param.getFileName());
InputStream is = param.getInputStream();
Document attachment = new Document(is);
attachment.copyToFile(new File(param.getFileName().split("/")[1]));
attachment.close();
} catch (IOException e) {
logger.debug(e.getMessage());
}
}

}


}

}

Avatar

Avatar
Ignite 5
Employee
workflowuser
Employee

Likes

133 likes

Total Posts

443 posts

Correct Reply

70 solutions
Top badges earned
Ignite 5
Ignite 3
Ignite 1
Give Back 50
Give Back 5
View profile

Avatar
Ignite 5
Employee
workflowuser
Employee

Likes

133 likes

Total Posts

443 posts

Correct Reply

70 solutions
Top badges earned
Ignite 5
Ignite 3
Ignite 1
Give Back 50
Give Back 5
View profile
workflowuser
Employee

25-06-2020

the original answer has been removed. Please follow the steps mentioned elsewhere in this post

Avatar

Avatar
Ignite 1
Level 7
GirishBedekar
Level 7

Likes

162 likes

Total Posts

232 posts

Correct Reply

36 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile

Avatar
Ignite 1
Level 7
GirishBedekar
Level 7

Likes

162 likes

Total Posts

232 posts

Correct Reply

36 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile
GirishBedekar
Level 7

26-06-2020

You can decompile using any java decompiler online 

there is interface and servlet that makes up the code

Avatar

Avatar
Ignite 5
Employee
workflowuser
Employee

Likes

133 likes

Total Posts

443 posts

Correct Reply

70 solutions
Top badges earned
Ignite 5
Ignite 3
Ignite 1
Give Back 50
Give Back 5
View profile

Avatar
Ignite 5
Employee
workflowuser
Employee

Likes

133 likes

Total Posts

443 posts

Correct Reply

70 solutions
Top badges earned
Ignite 5
Ignite 3
Ignite 1
Give Back 50
Give Back 5
View profile
workflowuser
Employee

25-06-2020

When you add attachments to AF they are stored in tmp location. Every time an attachment is added to AF you can use the event handler to get the location of the file and write that location to the hidden field in your AF. When you form is submitted your servlet can extract the attachments from that location and do the needful

I am attaching a simple form with a custom client lib. Preview the form and add attachments.You should see the text field populated with the path to the attachments

https://documentcloud.adobe.com/link/track?uri=urn:aaid:scds:US:54646349-ac33-4d87-8813-95861ce78bfc

 

import the two packages using package manager

then preview the TestAttachments form

add a couple of attachments

you should see the path of the attachments written to the text box

 

Avatar

Avatar
Ignite 1
Level 7
GirishBedekar
Level 7

Likes

162 likes

Total Posts

232 posts

Correct Reply

36 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile

Avatar
Ignite 1
Level 7
GirishBedekar
Level 7

Likes

162 likes

Total Posts

232 posts

Correct Reply

36 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile
GirishBedekar
Level 7

25-06-2020

You want to access attachments after the form is submitted?

are you using AEM workflow?

Avatar

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,129 likes

Total Posts

6,140 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,129 likes

Total Posts

6,140 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile
kautuk_sahni
Community Manager

11-05-2020

@Vish_dhaliwal @Arun_Patidar  Any pointers here?