Restrict the uploading of certain file types

Dogan Can March 12, 2014

Hi,

I want to restrict the uploading of certain file types. I tried to listen attachment event but the event is triggered after the file uploaded so it is useless.

I want to check the file type while uploading so the file won't be uploaded to server.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Steve Gerstner [bridgingIT]
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.
March 13, 2014

Have you tried a servlet filter on /pages/doattachfile.action ?

Dogan Can March 16, 2014

I haven't tried servlet filter yet. Can you help me, how can I use it to filter attachments?

Steve Gerstner [bridgingIT]
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.
March 16, 2014

Check this out:

https://developer.atlassian.com/display/DOCS/Servlet+Filter+Plugin+Module

Here is a little general how-to about servlet-filters:

http://www.oracle.com/technetwork/java/filters-137243.html

The only thing you have to do is to check the mime type of your upload and to decide if it's allowed or not...

Dogan Can March 16, 2014

Thank you, but after checking mime type of the file the request is not completed and it shows me "the page couldn't find" error even I upload an accepted file. What should I do no handle this situation and how can I display error message on the page like reacihng maximum file size limit?

Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 17, 2014

Why do you need to display an error for exceeding a maximum file size limit when Confluence already supports this out of the box? https://confluence.atlassian.com/display/DOC/Configuring+Attachment+Size

Dogan Can March 17, 2014

Joseph, I didnot mean display error for exceeding a maximum file size limit, I meant "as red error line appear in the page when error for exceeding a maximum file size limit".

And it is not the main problem, the problem is that after getting file extension what should I do to let the upload process ends if extension is acceptable or do not let the upload process and return the previous page.

if (!item.isFormField())
    if(item.getContentType().equals("application/x-msdownload"))
        return;// What should I do??????????

Dogan Can March 23, 2014

Issue has not been solved yet. Any help will be appreciated.

Steve Gerstner [bridgingIT]
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.
March 24, 2014

You can send a redirect to an error page, or try to figure out, how you can smash the upload action.

Another option would be to override the upload action with the conveyor-plugin. You can add your own code with your checks.

TAGS
AUG Leaders

Atlassian Community Events