Find Questions…

Close ×
First time here? Check out the FAQ!

Restrict attachment based on file type

Mizan asked this question · 11,024 karma ·

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 :)

1171 views

Mizan · 11,024 karma ·

Ideas , suggestions welcomed

2 Answers:

Niels Jaeckel · 2,317 karma ·

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 · 11,024 karma ·

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 · 2,718 karma ·

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 :)

Niels Jaeckel · 2,317 karma ·

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

·2 users liked this

Mizan · 11,024 karma ·

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 .

Niels Jaeckel · 2,317 karma ·

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

Niels Jaeckel · 2,317 karma ·

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

·1 user liked this

Naren · 2,718 karma ·

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.

Tam Nguyen · 251 karma ·

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

Niels Jaeckel · 2,317 karma ·

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

Looking for something else?

Find Questions…

or Browse other questions tagged:

or Ask a Question