How to get full path when upload file choose desktop file workflow? | Community
Skip to main content
Level 3
December 23, 2018
Solved

How to get full path when upload file choose desktop file workflow?

  • December 23, 2018
  • 1 reply
  • 10005 views

Hi Team,

I done customization for startworkflow.jsp("/libs/cq/gui/components/authoring/workflow/startworkflow/startworkflow.jsp").

When click upload file choose option getting fakepath append filename,How to get full path directory need to send email attachment.

I am not able  send file attached by using fakepath. error message : java.io.FileNotFoundException: C:\fakepath\testJcrcontent.txt(The system cannot find the path specified).

EmailAttachment attachment = new EmailAttachment();

  attachment.setPath("C:\fakepath\testJcrcontent.txt");

        attachment.setDisposition(EmailAttachment.ATTACHMENT);

        attachment.setDescription("Any Description");

        attachment.setName("Any name you can set");

Thanks

Kotireddy

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Gaurav-Behl

Pick the file using File API like   File file = new File(path_to_file); and then use file.getPath();

Alternatively, if you want to use a generic solution rather than a system dependent folder structure, try this -

File directory = new File("."); -- current WD for AEM, map the file path relative to AEM directory somewhere outside crx-quickstart

String path = directory.getCanonicalPath() + File.separator + LOCAL_FOLDER + File.separator;  -- File.separator would work both on Win & Linux

File file = new File(path + filename);

attachment.setPath(file.getPath());

1 reply

Gaurav-Behl
Gaurav-BehlAccepted solution
Level 10
December 24, 2018

Pick the file using File API like   File file = new File(path_to_file); and then use file.getPath();

Alternatively, if you want to use a generic solution rather than a system dependent folder structure, try this -

File directory = new File("."); -- current WD for AEM, map the file path relative to AEM directory somewhere outside crx-quickstart

String path = directory.getCanonicalPath() + File.separator + LOCAL_FOLDER + File.separator;  -- File.separator would work both on Win & Linux

File file = new File(path + filename);

attachment.setPath(file.getPath());

Gaurav-Behl
Level 10
May 31, 2021
This is correct, browsers are restricted to local filesystem access by default otherwise anybody could run malicious scripts. A better way is to ask for some form of "user-input" so that user has to key-in the required info. Based on your requirements, you may have to explore alternatives. P.S. Absolute file path will vary based on underlying OS and file/folder sharing permissions as well.