Restrict attachment based on file type

Mizan
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.
January 4, 2012

Hi ,

I want to restrict uploading of attachments based on file type for example .exe ,.bat.

I was able to automatically change the status when we attach a file . Is there an available plugin which provides this functionality ?

can anyone plz guide me how i can apply such filter which restricts attaching a specified file type ?

Thanx :)

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

4 votes
Answer accepted
NielsJ
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.
January 11, 2012

You could write a Plugin that exposes a Servlet Filter Module. This Servlet Filter decorates the attachment upload action, checks the filetype and display an error page (rendered directly or via redirect) to the user...

Mizan
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.
January 11, 2012

I was trying webwork plugin module to extend the attach file action but was not able to get the file name and check its extension and display an error message. I will try Servlet Filter Module , this will be the first time il use this module, thanx .

Naren
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.
January 9, 2013

Hi Niels,

Thanks for the above answer!

Even I am working on similar case. I tried writing a sevlet filter for intercepting the attachment upload request. But how should I get a attachment upload action and the file type being attached to the issue. I am looking at the AttachFile class. As I am new to this can you please guide me on this issue.

Any help will be much appreciated :)

NielsJ
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.
January 9, 2013

You could use org.apache.commons.fileupload.DiskFileUpload.parseRequest() in your servlet filter and then handle the FileItems.

Mizan
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.
January 10, 2013

Hi Niels ,

Can you please provide some code example on decorating the filter on the attach file action ?

Mizan
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.
January 10, 2013

Hi Niels ,

In my servlet filter i get file name , i check for the name and print an error message in the log . However I want to know how i can print an error message to the user .

NielsJ
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.
January 10, 2013

I found this example that provides some pointers for the implementation :)

http://www.d.umn.edu/~tcolburn/cs4531/slides/upload/java-source/UploadFilter.java.html

NielsJ
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.
January 10, 2013

Well, that's not easily possible. With the servlet filter you could just filter out unwanted files quietly.

If you want a nice error message for the user you could try overriding[1] the AttachFile action, define an own class that extends the class AttachFile and override the doValidation() method.

1: https://developer.atlassian.com/display/JIRADEV/Webwork+plugin+module#Webworkpluginmodule-OverridingaJIRAaction

Naren
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.
January 17, 2013

Well, Thanks Niels, I was able to restrict the attachments of certain types without using the servlet filter and by simply extending the AttachTemporaryFile action and displaying the error message upon attaching files of certain types.

Also you can try modifying the class files for this functionality, but have to keep a track of it during upgrades.

Like sanjay likes this
1 vote
Tam Nguyen
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.
January 11, 2012

You can make a plugin to do that. Implement com.atlassian.jira.issue.AttachmentManager, the default implementation is com.atlassian.jira.issue.managers.DefaultAttachmentManager

NielsJ
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.
January 11, 2012

I think it is not possible to exchange the DefaultAttachmentManager via a Plugin. You would have to edit the Spring configs directly...

0 votes
Akeles
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.
May 2, 2014

You might want to check out the Attachment Checker for JIRA plugin.

0 votes
Mizan
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.
January 11, 2012

Ideas , suggestions welcomed

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