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 get path of uploaded file in servlet from js

Avatar

Avatar
Boost 1
Level 1
sushmapoojitha
Level 1

Likes

2 likes

Total Posts

23 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Validate 1
Give Back
View profile

Avatar
Boost 1
Level 1
sushmapoojitha
Level 1

Likes

2 likes

Total Posts

23 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Validate 1
Give Back
View profile
sushmapoojitha
Level 1

30-05-2021

Hi there

I am trying to upload a file using type = "file" in aem front end and I want to read that file using servlet and get the data of the file. I already have a servlet in which I have hardcoded one link but I want to get the link of the file uploaded using the button in that place and get data of the file.
Can anyone help me with this?
Thanks in advance!!

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Affirm 25
Employee
PulkitJain
Employee

Likes

59 likes

Total Posts

62 posts

Correct Reply

27 solutions
Top badges earned
Affirm 25
Boost 50
Give Back 10
Establish
Boost 25
View profile

Avatar
Affirm 25
Employee
PulkitJain
Employee

Likes

59 likes

Total Posts

62 posts

Correct Reply

27 solutions
Top badges earned
Affirm 25
Boost 50
Give Back 10
Establish
Boost 25
View profile
PulkitJain
Employee

30-05-2021

@sushmapoojitha 

When you add attachments to an adaptive form, the attachments are stored in a temporary location in the CRX repository. 

You can also create a servlet to store the form attachments in a new location in the CRX repository and then access the file directly.

String fileName = attacmenPath.split("/")[1];
InputStream is = request.getPart(attacmenPath).getInputStream();
Document aemFDDocument = new Document(is);
String crxPath = saveDocumentInCrx("/content/afattachments", fileName, aemFDDocument);

 

Hope this helps!

Answers (2)

Answers (2)

Avatar

Avatar
Springboard
Level 10
Mayank_Gandhi
Level 10

Likes

309 likes

Total Posts

1,131 posts

Correct Reply

184 solutions
Top badges earned
Springboard
Establish
Validate 1
Contributor 2
Ignite 5
View profile

Avatar
Springboard
Level 10
Mayank_Gandhi
Level 10

Likes

309 likes

Total Posts

1,131 posts

Correct Reply

184 solutions
Top badges earned
Springboard
Establish
Validate 1
Contributor 2
Ignite 5
View profile
Mayank_Gandhi
Level 10

01-06-2021

@sushmapoojitha Why not just create a custom file upload widget and as users upload the file convert it to base64 and create an HTML link in the form. You don't need a servlet for this, it can be done in vanilla JS. 

Avatar

Avatar
Springboard
Level 10
Mayank_Gandhi
Level 10

Likes

309 likes

Total Posts

1,131 posts

Correct Reply

184 solutions
Top badges earned
Springboard
Establish
Validate 1
Contributor 2
Ignite 5
View profile

Avatar
Springboard
Level 10
Mayank_Gandhi
Level 10

Likes

309 likes

Total Posts

1,131 posts

Correct Reply

184 solutions
Top badges earned
Springboard
Establish
Validate 1
Contributor 2
Ignite 5
View profile
Mayank_Gandhi
Level 10

31-05-2021

@sushmapoojitha " absolute path of the uploaded file", So you want to expose part of your server with an absolute path that is accessible to an external user, Not a great idea.

 

How many links do you want to show on the form?