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.
Community moderators have prevented the ability to post new answers.
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());
Thanks @Dipti :)
It worked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you post a code sample ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.