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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted 6 hours ago in Off-topic

Miscellaneous Monday - CreatatronV3

You may remember, not so long ago, that together we invented the most evil of machines: The Destructo5000!  The effects of missing Durian rippled over nations. Complete chaos as goat chee...

55 views 4 2
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you