Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to default to "view" (and not download) for file attachments on a page in Confluence?

Abhay Patil June 2, 2017

Confluence on cloud. About attachments in a page. Attached file is a MS Word doc that is displayed on the page using "attachment" macro. When one clicks on the file name link on the page, tthe file is downloaded. Expected intuitive default behaviour should be that the file is opened for viewing. Can we make that happen? 

(Note: One can click on the arrow by side and choose view option. Edited the description for clarity and context.)

6 answers

1 vote
Davin Studer
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.
November 29, 2018

If you are on Confluence Server or Data Center you could create a user macro that you can drop onto your page that will change the file links in the attachments macro to preview the document instead of downloading it. Here is the user macro.

Macro Name:
preview_attachments

Macro Title:
Preview Attachments

Description:
This will change the links in the attachments macro to preview the attachment instead of downloading it.

Macro Body Processing:
No macro body

Template:

## Developed by: Davin Studer
## Date created: 11/29/2018
## @noparams

<script type="text/javascript">
//<![CDATA[
    AJS.toInit(function(){
        AJS.$('.plugin_attachments_container a.filename').click(function(e){
            // This will intercept clicks on the file links and programmatically click the preview button instead.
            e.preventDefault();
            
            var attachmentId = AJS.$(this).closest('tr.attachment-row').attr('data-attachment-id');
            
            AJS.$('.attachment-summary-' + attachmentId + ' .attachment-buttons a.aui-button.previewAttachmentLink').click();
        });
    });
//]]>
</script>
Andreas Gounaris April 10, 2019

Very nice, handy and simple!

Thx

Andreas Gounaris August 7, 2019

After working with this macro for sometime, I discovered that, when going to preview using the filename link, some buttons above the preview area do not work. These are: the Close button (the X symbol), the upload button and the toolbar, when you hover over the page, to pin, magnify etc appears randomly if not at all.

This behavior does not occur when clicking the preview button instead.

There must be something to do with the event fired from a different source element.

Or maybe, the e.preventDefault() cancels the bubble and this misses something in the chain of events which come after. Haven't tried to comment it out to see what will happen. 

False sentence, the preventDefault cancels the download action and this is correct.

0 votes
Oscar Brinkhof December 13, 2018

Hi Davin,

I've used the macro preview_attachments it works within the same page where the files are in.

However we like to use one page with a filelist as a central page to store documents including labels.  Other pages are using as much as possible dynamic macro's e.g. content per label. Using the macro preview_attachments before a macro content by label still download the file instead of give a preview.

Did I do something wrong or does the preview_attachment not work in combination with other macro's

Davin Studer
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.
December 13, 2018

I designed that user macro specifically to work with the attachments macro. It would have to be adapted to work with other macros.

Oscar Brinkhof December 14, 2018

Hi Davin,

Quote Davin: "I would have to be adapted to work with other macros." 

I don't know if I understand you well. Does this mean you make it work with other macros? If not we have to make other decisions the way we use Confluence.

Best regards

Davin Studer
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.
December 14, 2018

As the user macro is currently written it only works with the attachments macro. That was what the original poster of the question was asking for.

0 votes
Arun November 28, 2018

Hi Davin Studer,

We would like to see Doc attachments should be display/view for the regular users. Let us know us you suggestions.

0 votes
Veve October 10, 2018

I'm interested in the same thing. Links to attached files are displayed at various places, where the View option is not available at all.

For example on the "Labelled content" page, in Search results, etc.

(We are moving all our previous requirements into Confluence now, as attachments. Conversion one by one was really painful, I did it for a dozen, then decided against it.)

0 votes
AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 2, 2017

Please let me know what version you are using. On my Confluence 6.2.x instance a link to a Word doc on a page will preview the document, but if you go to the attachments list for the page, clicking on the title there will download the attachment.

Abhay Patil June 2, 2017

I am using Confluence on the cloud. 

Confluence 1000.1457.1

0 votes
Davin Studer
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.
June 2, 2017

Are you referring to the attachments macro or the attachments section on the page?

Abhay Patil June 2, 2017

I attached a file and then used attachment macro to show that file on the page. I can now get to the file using the attachment icon at the top or by clicking on the file name in the page. When I click on the file name, it gets downloaded. I wish to change the behavior to "view" when I click the file. Following is the screen shot of the page. ConfluenceAttachment.png

Like Tom Hawkins likes this
Davin Studer
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.
June 2, 2017

Ah, if you were using the server version I could give you an idea to try, but with the cloud version what I would have suggested is not possible.

jaytaala January 12, 2018

Hi David, I'm using confluence server and am interested in your idea as I would prefer to click and preview the file in a file-list macro (rather than download straight away).

Ada Kardos April 25, 2018

Hi Davin, I am also using server and would love to hear your idea for this. 

Joseph Isom June 7, 2018

Hello @Davin Studer,

I am running server and would also like to hear your recommendation.

Thanks

Joseph 

Ron Kaledas April 14, 2022

Ditto!  Davin, I know this is old, but hopefully you're still getting updates from this topic?

 

Atlassian - seems like this is a feature we'd like to have, to be able to change what happens when you click on a link/filename?

Like # people like this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events