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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Retrieving File Attachments from adobe adaptive form

mohamedn4455443
Level 4
Level 4

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

1 Accepted Solution
workflowuser
Correct answer by
Employee
Employee

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

View solution in original post

0 Replies
workflowuser
Employee
Employee
i will send you working sample in the next 48 hours or so
mohamedn4455443
Level 4
Level 4
Well, thank you very much for your help, Waiting for you
workflowuser
Employee
Employee

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

mohamedn4455443
Level 4
Level 4
This is very good. It works fine and I can get the file name and attachment path in the stdout file, Can you share the handleafsubmission.handleafsubmission maven project with me please?
GirishBedekar
Level 9
Level 9

You can decompile using any java decompiler online 

there is interface and servlet that makes up the code

mohamedn4455443
Level 4
Level 4
I already did, but some files didn't find such as comergeandfusem.mergeandfuse.getservice userresolver.get resolver.jar
workflowuser
Employee
Employee

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());
}
}

}


}

}

workflowuser
Correct answer by
Employee
Employee

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