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

how to pass file from jquery to servlet in aem?

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct Reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct Reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

27-06-2019

Hi,

Can anyone help me out in this usecase where attachments are sent as email in aem. I am stuck at a point on how to pass file from jquery ajax to servlet and then passing it as parameter to emailService.

Joerg HohArun Patidarsmacdonald2008

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,358 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,358 likes

Total Posts

3,228 posts

Correct Reply

918 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

27-06-2019

In jquery you can pass the file path and read file in Servlet and convert in InputStream and use inside your map

File file = new File(filePath);

InputStream is = new FileInputStream(file);

ByteArrayDataSource(InputStream is, String type)

Email

Email API

String attachment1 = "This text should be in the attache txt file.";
  Map<String, DataSource> attachments = new HashMap<>();
  attachments.put("attachment1.txt", new ByteArrayDataSource(attachment1, "text/plain"));

Answers (2)

Answers (2)

Avatar

Avatar
Give Back 5
Level 4
joeb21688728
Level 4

Likes

33 likes

Total Posts

60 posts

Correct Reply

8 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 25
Give Back 10
Give Back
View profile

Avatar
Give Back 5
Level 4
joeb21688728
Level 4

Likes

33 likes

Total Posts

60 posts

Correct Reply

8 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 25
Give Back 10
Give Back
View profile
joeb21688728
Level 4

27-06-2019

Here is an older doc that covers HOW TO pass a file to an AEM servlet using JQuery:

Adobe Experience Manager Help | Uploading files to Adobe Experience Manager DAM using AssetManager A...

Avatar

Avatar
Establish
Level 6
antoniom5495929
Level 6

Likes

91 likes

Total Posts

212 posts

Correct Reply

39 solutions
Top badges earned
Establish
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Establish
Level 6
antoniom5495929
Level 6

Likes

91 likes

Total Posts

212 posts

Correct Reply

39 solutions
Top badges earned
Establish
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile
antoniom5495929
Level 6

27-06-2019

Hi,

what you can try to do is to encode your file in base64 and then send it as a string parameter into your servlet.

Inside your servlet you just need to use some snippet like the following:

Base64.getDecoder().decode(fileBase64)

In order to get the file and decode it into your serlvet.

Let me know if this could be helpful.

Thanks,

Antonio