Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7731821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:34:36+00:00 2026-06-01T06:34:36+00:00

I’m trying to customize the Liferay Web Form portlet to accept file upload, and

  • 0

I’m trying to customize the Liferay Web Form portlet to accept file upload, and I’ve gotten pretty much everything working except attaching the file to the email to be sent.

Getting fields from the form:

public void saveData(ActionRequest actionRequest, ActionResponse actionResponse) {

...

File uploadedFile = null;

...

Map<String,String> fieldsMap = new LinkedHashMap<String,String>();

// Create a FileItemFactory for disk-based file items
DiskFileItemFactory factory = new DiskFileItemFactory(1073741824, new File("/temp"));

// Create a new file upload handler
PortletFileUpload upload = new PortletFileUpload(factory);
upload.setSizeMax(67108864);

// Parse the request
List<FileItem> items = upload.parseRequest(actionRequest); 

int i = 1;

Iterator iter = items.iterator();

// Throw away the hidden field, don't need it
FileItem dud = (FileItem)iter.next();

while (iter.hasNext()) {

    FileItem item = (FileItem)iter.next();

    String fieldLabel = preferences.getValue(
        "fieldLabel" + i, StringPool.BLANK);

    String fieldType = preferences.getValue(
            "fieldType" + i, StringPool.BLANK);

    if (Validator.isNull(fieldLabel)) {
        break;
    }

    if(!fieldType.equals("file")) {
        String fieldValue = item.getString();
        fieldsMap.put(fieldLabel, fieldValue);
    } else {
        String fieldName = item.getName();
        uploadedFile = new File(fieldName);
        item.write(uploadedFile);
    }
        i++;
}
...

     if(sendAsEmail) {
         emailSuccess = sendEmail(fieldsMap, preferences, uploadedFile);
     }
}

And then the construction and sending of the email:

protected boolean sendEmail(Map<String, String> fieldsMap, PortletPreferences preferences, File uploadedFile) {

    MailMessage mailMessage = new MailMessage(fromAddress, toAddress, subject, body, false);

    if(uploadedFile != null) { // i.e., there was 'file' field up above
        mailMessage.addAttachment(uploadedFile);
    }

    MailServiceUtil.sendEmail(mailMessage);


    if(uploadedFile != null) {
       uploadedFile.delete();
    }

}

I get the following console error when attempting to process a file upload and attach the file to the message:

16:09:49,597 ERROR [MailEngine:489] IOException while sending message
16:09:49,598 ERROR [MailEngine:154] java.io.FileNotFoundException: helpdesk_.png (No such file or directory)

Do I have my DiskFileItemFactory configured correctly? What could I be doing wrong?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:34:37+00:00Added an answer on June 1, 2026 at 6:34 am

    It appears that MailServiceUtil subsystem spins off a thread to do the actual sending of the email, and does not wait for it to return (hence, thread). So after the MailServiceUtil.sendEmail() call, I was immediately deleting the file to be attached BEFORE it actually got a chance to be sent!

    I’m going to look into some type of wrapper for the MailServiceUtil that I can pass the file object into and then once its actually sent do the delete.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to render a haml file in a javascript response like so:
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.