PDF does not automatically show in browser after upgrade from 3.3.0 to 4.0.6

Added by CM Gui 6 months ago

Hi All

We recently upgraded Redmine from 3.3.0 to 4.0.6. In Redmine 3.3.0, image and PDF attachments will automatically open in the same browser window as the Redmine site (replacing the site). After upgrading to 4.0.6, image attachment also opens in the same browser window as the Redmine site but now it is displayed inside the site (inline). But when we tried to open a PDF attachment, this message appears: "No preview available. Download the file instead.".

We understand that Redmine is trying to improve things by displaying the attached image inline instead of automatically downloading the image and letting the browser do the work of displaying the image and overwriting the site with the image. Perhaps for PDF attachment, Redmine should let it download automatically and then let the browser do the displaying in a NEW browser tab (e.g., html code: target="_blank").

Does anybody know how to tweak the Redmine code to do this? That is, when it comes to PDF attachment, clicking on it will automatically download it. And then the browser by default will take over and display it. Maybe making it display in a new browser tab will involve a lot of tweaking, but making it download automatically should be easier?

There is a hack to display PDF but it doesn't seem to apply to Redmine 4.x.
[[https://www.redmine.org/boards/3/topics/26320]]

There are plugins like lightbox2 and Redmine Preview PDF ([[https://www.redmine.org/plugins/redmine_preview_pdf]]).
We don't really like lightbox2 and the Redmine Preview PDF isn't supported in Redmine 4.x.

Thank you very much in anticipation.

cmgui

P.S. Found out that even clicking on a zip file attachment will open the "No preview available" page. This is really a downgrade from 3.3.0. If it is not an image attachment, clicking the attachment link should automatically download it as in 3.3.0. Thank you.

P.S. Found out from the links before that this is "expected" behavior, i.e., by design. Not sure if this is good design. IMHO, if it is image attachment, by all means, open it in a view page in the Redmine site. But if it is not an image, e.g., PDF or zip file attachment, why not just let the attachment download automatically when clicked?

[[https://www.redmine.org/issues/28567]]

[[https://www.redmine.org/issues/22482]]

[[https://www.redmine.org/issues/25988]]

[[https://www.redmine.org/issues/22483]]

Anybody knows how to revert to 3.3.0 way of downloading non-image attachment links? Thank you.

Update: 012420
We undid some of the changes in this link [[https://www.redmine.org/issues/25988]] and it seems to work.

Replacing /app/helpers/issues_helper.rb, /app/models/attachment.rb, /app/views/attachments/_links.html.erb
and /app/views/files/index.html.erb with Redmine 3.3.0 version files doesn't work.
Did this:

/app/helpers/issues_helper.rb

#        value = link_to_attachment(atta, only_path: options[:only_path])
#        if options[:only_path] != false
# commented above 2 and added below 2
        value = link_to_attachment(atta, :download => true, :only_path => options[:only_path])
        if options[:only_path] != false && (atta.is_text? || atta.is_image?)

/app/models/attachment.rb

#                :url => Proc.new {|o| {:controller => 'attachments', :action => 'show', :id => o.id, :filename => o.filename}}
# commented out above and added below
                 :url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}}

acts_as_activity_provider :type => 'files',

/app/views/attachments/_links.html.erb

<!--    <%= link_to_attachment attachment, class: 'icon icon-attachment' -%> -->
<!-- commented out above and added below -->
<%= link_to_attachment attachment, :class => 'icon icon-attachment', :download => true -%>

/app/views/files/index.html.erb

<!--      <td class="filename"><%= link_to_attachment file, :title => file.description -%></td> -->
<!--  commented out above and added below -->
      <td class="filename"><%= link_to_attachment file, :download => true, :title => file.description %></td>