how to pass file from jquery to servlet in aem? | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Jun 27, 2019 4:05 PM UTC

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"));

Arun Patidar

3 replies

Jun 28, 2019 12:53 AM UTC

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 API

Translate
arunpatidar
arunpatidarAccepted solution
New Participant
Jun 27, 2019 4:05 PM UTC

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"));

Translate
Arun Patidar
antoniom5495929
Level 7
Jun 27, 2019 11:42 AM UTC

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

Translate