Sending the uploaded image in the form field as email attachment

Hi,

Once a form is submitted, We need to send a confirmation mail along with the image uploaded.

But we are facing issue to receive the image at the backend, can anyone please respond if they

have done this before.

Thanks
Nirish

Hi Nirish,
I presume you are using the ootb ConfirmationBehavior? I think it doesn’t support this case.
The MailFormDataBehavior (for mailing a form to the back-end) does support uploads so a way out is to create your own behavior that combines the two.

HTH
Jeroen

[1] Submission Confirmation Behavior - Bloomreach Experience - Open Source CMS

Hi jeroen,

Thanks for the response, we are not using ootb confirmation behaviour.
We are using below code in frontend:

form method=“post” enctype=“multipart/form-data”
input type=“file” name=“add-images” class=" " data-max-size=“1”
form

In the backend we have a class which extends EformComponent and in that we are using below code to get form data:

FormBean form = getFormBean(request);
String[] formFields = fieldsInsideAForm(form);
FormMap map = new FormMap(request,formFields);

Now the issue is we need to get the image file from formField and sent it to an email.
Can you please share how it can be solved

you need to parse file parts yourself. You can check old forms code base as an example, mainly:

http://svn.onehippo.org/repos/hippo/attic/forge/easy-forms/easy-forms/trunk/hst/src/main/java/org/onehippo/forge/easyforms/util/FileUploadUtil.java

and

http://svn.onehippo.org/repos/hippo/attic/forge/easy-forms/easy-forms/trunk/hst/src/main/java/org/onehippo/forge/easyforms/hst/EasyFormComponent.java

all project: http://svn.onehippo.org/repos/hippo/attic/forge/easy-forms/easy-forms/

1 Like