How to get path of uploaded file in servlet from js | Community
Skip to main content
New Participant
May 31, 2021
Question

How to get path of uploaded file in servlet from js

  • May 31, 2021
  • 3 replies
  • 2078 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Mayank_Gandhi
Employee
June 1, 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. 

Mayank_Gandhi
Employee
May 31, 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?

 

New Participant
June 1, 2021
@mayank_gandhi, it is just one link which i need, and this cannot be used by all users, it will be used only by a certain set of people and also I don't need to store the uploaded file, i just need to get link of it send to servlet and get data inside the file. It is for one time purpose, no need of storing file inside aem.
Pulkit_Jain_
Employee
May 31, 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!

New Participant
May 31, 2021

Hi @pulkit_jain_, I don't want to save the uploaded attachment, it's just after uploading file using one button and on click on submit button, my servlet which gets active by the submit button should take the absolute path of the uploaded file and should be able to read the data in that file.
or can you help me get the absolute path of the uploaded file in aem js itself?