It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Custom Upload, and Attachment Handler

I'm writing an app that needs to use java to recoeve a small upload, and attach it to several issues (upload can be duplicated if necessary). I have created a handler servlet, but I'm struggeling with finding the proper API classes that handle the attachment code.

does Jira have a temp folder thats suitable for uploading to?

where should the file end up?

which classes handle file upload?

Thanks for your help...

2 answers

1)

You probably need:

MultiPartRequestWrapper mprw = (MultiPartRequestWrapper) ServletActionContext.getMultiPartRequest();
if (mprw!=null && mprw.getFileNames().hasMoreElements())
{
  byte[] data=null;
  Enumeration<String> fileNames = mprw.getFileNames();
  if (fileNames.hasMoreElements())
  {
    while(fileNames.hasMoreElements())
    {
      String fileName = fileNames.nextElement();
      File file = mprw.getFile(fileName);		
...

2)

Try getting ComponentAccessor.getComponent(JiraHome.class);

That will give you .getDataDirectory() , which is your JIRA_HOME/data folder, allowing you to create a temp file in JIRA_HOME/tmp or your own location.

Any Ideas on how to programatically attach a File object to an issue?

points encourage additional answers :) You need to create an attachment.

AttachmentManager attachmentManager = ComponentManager.getInstance().getAttachmentManager();

for some reason, the ... 
MultiPartRequestWrapper mprw = (MultiPartRequestWrapper) ServletActionContext.getMultiPartRequest();

is resolving to null?

is there something special I need in my servlet config?

&lt;servlet name="dataHandler" key="bamHandler" class="com.foo.BarServlet"&gt;
     &lt;description&gt;&lt;/description&gt;
     &lt;url-pattern&gt;/dataHandler&lt;/url-pattern&gt;
&lt;/servlet&gt;

Thanks again :)

 
For some reasong the mprw is comming back null? any ideas?

MultiPartRequestWrapper mprw = ServletActionContext.getMultiPartRequest();



Also, is there something special I need in my servlet config to support MultiPart Requests?

<servlet name="dataHandler" key="bamHandler" class="com.foo.BarServlet">
     <description></description>
     <url-pattern>/dataHandler</url-pattern>
</servlet>

Thanks again :)

for some reason, the ... 
MultiPartRequestWrapper mprw = (MultiPartRequestWrapper) ServletActionContext.getMultiPartRequest();

is resolving to null?

is there something special I need in my servlet config?

&lt;servlet name="dataHandler" key="bamHandler" class="com.foo.BarServlet"&gt;
     &lt;description&gt;&lt;/description&gt;
     &lt;url-pattern&gt;/dataHandler&lt;/url-pattern&gt;
&lt;/servlet&gt;

Thanks again Andy :)

 

Uh no, the ServletActionContext is part of webwork, well, it may be a utiloity class, but I've only used it inside an action. The patter to use is [HTML form] -> posts -> [Action] from which the above code works to extract the posted data.

Not to say your approach woudn't work, but Ive not had a compelling reason to even try, this works.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in United States

Live! - Austin ACE -- Summer BASH 2019

Hey Austin! Come join us for our 2019 Atlassian Community Summer BASH as we transition ourselves into party status! Bring an attachment, log a great time, and collaborate with new friends as we celeb...

31 views 0 0
View post

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you