how to get inside Webwork Action from velocity form.

Vikash Kumar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 22, 2013

how to get File inside Webwork Action from velocity form.

All properties are getting populate into Webwork action directly except the <input type="file">.

Any help will be appreciated.

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Dipti Ranjan Behera
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 11, 2013

Hi @Vikas,

Don't do TemporaryAttachement , use Attachment object and

use File file = AttachmentUtils.getAttachmentFile(attachment); instead of ta.getFile() in DataSource source = new FileDataSource(ta.getFile());

Vikash Kumar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2013

Thanks @Dipti :)

It worked.

0 votes
roberto.lopez June 2, 2014

I have the same problem. I lost the attachment

0 votes
Dipti Ranjan Behera
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2013

@Vikas,

use this com.atlassian.jira.util.AttachmentUtils class to get the attachment file in physical.

Rest sending attachment through can be found thru google.

Vikash Kumar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2013

Hi @Dipti,

Thanks for your quick reply.

I am able to get attachment. But the problem is with the send email with attachment only. As I am gettng error response time out however i have made the time interval of 60 sec in jira outgoing mail. Can send email without attachment successfully.

Did lots of google for send email with attachment but no solution so far.

I tried with both gmail/yahoo service to send email with attachment from jira email queue. I guess, something I am missing for email attachment.

Any help on this will be appriciated.

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2013

Can you post a code sample ?

Vikash Kumar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2013

Hi @Boris,

Please find code snippet below.

protected String doExecute() throws Exception {//AttachFile

...

...

SMTPMailServer mailServer =MailFactory.getServerManager().getDefaultSMTPMailServer();

if(emailFormat == null || emailFormat.length()==0){

emailFormat = "HTML";

}

Email email = new Email(loggedInUser.getEmailAddress());

email.setFrom(mailServer.getDefaultFrom());

email.setSubject(emailSubject);

email.setMimeType(emailFormat.equalsIgnoreCase("HTML") ? "text/html" : "text/plain");

email.setBody(emailBody);

System.out.println(recipientCc.toString());

String emailIdList = EmailUtil.convertToEmailAddress(recipientTo);

email.setCc(emailIdList);

emailIdList = EmailUtil.convertToEmailAddress(recipientBcc);

email.setBcc(emailIdList);

List<File> attachments = new ArrayList<File>();

if (!attachmentAboutToBeAdded.isEmpty())

{Multipart multipart = new MimeMultipart();

for(TemporaryAttachment ta: attachmentAboutToBeAdded){ attachmentIds.add(ta.getId());

attachments.add(ta.getFile());

try{

MimeBodyPart attachment = new MimeBodyPart();

DataSource source = new FileDataSource(ta.getFile());

attachment.setDataHandler(new DataHandler(source));

attachment.setFileName(ta.getFilename());

attachment.setDisposition("Attachments");

attachment.addHeader("attach-header", "rendom value");

multipart.addBodyPart(attachment);

}catch(Exception e){

}

}email.setMultipart(multipart);

}

SingleMailQueueItem item = new SingleMailQueueItem(email);

ComponentAccessor.getMailQueue().addItem(item);

return SUCCESS;

}

0 votes
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2013

You can not set value of a file html element due to security reasons - it's restricted by the browsers, as otherwise it will allow you to steal any file from the client file system.

Can you give more context here - why do you need to populate the file input ?

Vikash Kumar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2013

Sorry for being late, i was out of context.

Well my requirements goes here:

I am trying to upload single file at a time to an existing issue from my custom plugin and at the same time I am trying to send that attachment from there only.

Now issues I am facing is.

Part A:

1) I am not able to get multipart request object in my web action I used ActionContext.getMultiPartRequest() which is returning null. Although, tried all these in my form

<form enctype="multipart/form-data" and multipart/mixed ...

<input class="ignore-inline-attach" type="file" id="upload-file" name="uploadFile" title="upload file"> [One file at a time, i guess no problem with this]

-

-

-...

Nothing helped me to get the multipart request.

Part B:

2) I am not able to send attachment with email as it give timeout exception, i tried to increase the timeout=60000, it again fails.

Thanks

Vikash

Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2013

For point 1 try using

new ServletFileUpload().parseRequest(getHttpRequest())

For point 2 - can you describe it in details as I can't understand what are you tring to do. Are you trying to send a mail from Java ?

Vikash Kumar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 10, 2013

@boris : Yes I want to send email from my java action class for that I need file object over there.

Can you please help me in sending email with attachment as well.

I am able to send email but failed to send with attachment.

Thanks,

Vikash

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events