Project

General

Profile

Actions

Defect #17403

closed

Unknown file size while downloading attachment

Added by Amit Baswa over 10 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Normal
Category:
Attachments
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed
Affected version:

Description

Hi Redmine,

When the download starts in Chrome,IDM,etc it shows the download size as unknown. However the file size can be seen in issues attachment ares, but while download it doesn't shows the file size
I had attached which shows the exact concept, please check on it
Following are the details of my Redmine deployed environment:

Environment:
Redmine version 2.4.2.stable
Ruby version 2.0.0-p247 (2013-06-27) [x86_64-linux]
Rails version 3.2.16
Environment production
Database adapter Mysql2
SCM:
Subversion 1.6.11
Git 1.9.3
Filesystem
Redmine plugins:
redmine_auto_watch 1.0.0
redmine_issue_checklist 2.0.5
redmine_overdue_notification_task 0.3.0
redmine_work_time 0.2.14
sidebar_hide 0.0.7

Kindly let me know if there is any patch or solution on it.

Regards,
Amit


Files

Untitled.jpg (232 KB) Untitled.jpg Proof of issue Amit Baswa, 2014-07-07 09:55
Untitled.png (164 KB) Untitled.png 500 Internal Error after change in code Amit Baswa, 2014-07-08 09:33
Untitled.jpg (236 KB) Untitled.jpg Code worked :) , but resume not supported... :( Amit Baswa, 2014-07-11 10:01

Related issues

Related to Redmine - Feature #17452: Add support for download resume to attachmentsNew

Actions
Related to Redmine - Defect #19438: Webrick WARN: "Could not determine content-length of response body"Closed

Actions
Actions #1

Updated by Daniel Felix over 10 years ago

Hi there,

please try to add the following line above to this line in source:trunk/app/controllers/attachments_controller.rb#L57 your attachments_controller.


headers['Content-Length'] = File.size(@attachment.filename)

Please give a short feedback. Maybe you need to restart your rails app for this change to take affect.

Actions #2

Updated by Daniel Felix over 10 years ago

Just to be sure...

Cast the value to a string.


headers['Content-Length'] = File.size(@attachment.filename).to_s

Actions #3

Updated by Amit Baswa over 10 years ago

Thanks Daniel,

I will make changes as per instruction provided and update the issue with feedback.

Regards,
Amit

Actions #4

Updated by Amit Baswa over 10 years ago

Hi Daniel,

I changed the code as per above instruction, but after that I was unable to even download attachment file. It was showing 500 Internal Error.
Currently I had restored original code and the file is getting download with UNKNOWN size as usual.

Please let me know any other solution.

Attaching the proof of error.

Cheers,
Amit Baswa

Actions #5

Updated by Daniel Felix over 10 years ago

Sorry my fault. I've missed that attachments has a column filesize.
Please try this, this worked for me.

headers['Content-Length'] = @attachment.filesize.to_s

Sorry. :-D

Actions #6

Updated by Amit Baswa over 10 years ago

Thanks Daniel,

This worked for me too. Now I could see the file size while downloading it.

But,
I had one more issue with download. Attachment download currently does not support 'Resume'. Can we do something on it by which we can resume attachment download from where we had stopped. Because, if it is a large file then sometime it happens that due to internet issue the download stops and restart (because of no resume support).

Please find attachment for reference. Response is appreciated.

Cheers,
Amit

Actions #7

Updated by Jean-Philippe Lang over 10 years ago

  • Resolution set to Cant reproduce

Tested with 2.4 and 2.5, Content-Length header is properly set in the response.

Actions #8

Updated by Go MAEDA over 10 years ago

Jean-Philippe Lang wrote:

Tested with 2.4 and 2.5, Content-Length header is properly set in the response.

I cannot see Content-Length field in response header from www.redmine.org.

command:

curl -D /tmp/header.txt http://www.redmine.org/attachments/download/11948/Untitled.jpg > /dev/null

result:

$ cat /tmp/header.txt
HTTP/1.1 200 OK
Date: Sat, 12 Jul 2014 02:25:47 GMT
Server: Apache
ETag: "24c773e01c7142c2d13637ca78de6db9" 
Content-Disposition: inline; filename="Untitled.jpg" 
Content-Transfer-Encoding: binary
Cache-Control: private
X-UA-Compatible: IE=Edge,chrome=1
X-Request-Id: 4ebd53dba1113938b048d92079cfc16e
X-Runtime: 0.010945
X-Rack-Cache: miss
Transfer-Encoding: chunked
Content-Type: image/jpeg

Actions #9

Updated by Amit Baswa over 10 years ago

Amit Baswa wrote:

Thanks Daniel,

This worked for me too. Now I could see the file size while downloading it.

But,
I had one more issue with download. Attachment download currently does not support 'Resume'. Can we do something on it by which we can resume attachment download from where we had stopped. Because, if it is a large file then sometime it happens that due to internet issue the download stops and restart (because of no resume support).

Please find attachment for reference. Response is appreciated.

Cheers,
Amit

Hi,

Can you please let me know if above issue will track in this issue or should I open a new ticket for this?

--Amit

Actions #10

Updated by Go MAEDA over 10 years ago

Amit Baswa, you would be better to create a new issue. The resume feature is another topic from this.

Actions #11

Updated by Amit Baswa over 10 years ago

Thanks Go MAEDA

--Amit

Actions #12

Updated by Daniel Felix over 10 years ago

Jean-Philippe Lang wrote:

Tested with 2.4 and 2.5, Content-Length header is properly set in the response.

Tested this with 2.3 till 2.6-devel, no version sends a Content-Length header with the request. Maybe this is a setting in on your server?
I've tested it using apache with passenger.

The provided patch solved the issue for me.

Actions #13

Updated by Go MAEDA over 10 years ago

Another solution. Adds Content-Length field if it is not included in a response header.

Index: config/application.rb
===================================================================
--- config/application.rb    (revision 13317)
+++ config/application.rb    (working copy)
@@ -54,6 +54,8 @@

     config.session_store :cookie_store, :key => '_redmine_session'

+    config.middleware.use Rack::ContentLength
+
     if File.exists?(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
       instance_eval File.read(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
     end
Actions #14

Updated by Jean-Philippe Lang over 10 years ago

Daniel Felix wrote:

Tested this with 2.3 till 2.6-devel, no version sends a Content-Length header with the request. Maybe this is a setting in on your server?

The Content-Length header is set when running with Webrick. It's also set in the responses when running integration tests.

Using the Rack::ContentLength middleware seems to be a good option but I think it won't work if using X-Sendfile header (eg. config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache). Anyone tested it?

Actions #15

Updated by Toshi MARUYAMA over 10 years ago

  • Related to Feature #17452: Add support for download resume to attachments added
Actions #16

Updated by Toshi MARUYAMA over 10 years ago

  • Resolution deleted (Cant reproduce)
Actions #17

Updated by Toshi MARUYAMA over 9 years ago

  • Related to Defect #19438: Webrick WARN: "Could not determine content-length of response body" added
Actions #18

Updated by Go MAEDA about 9 years ago

Jean-Philippe Lang wrote:

Using the Rack::ContentLength middleware seems to be a good option but I think it won't work if using X-Sendfile header (eg. config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache). Anyone tested it?

I tested Apache + mod_xsendfile on CentOS 7 and it worked well. I could see a Content-Lengh header field.

Modifications:

Index: config/application.rb
===================================================================
--- config/application.rb    (revision 14625)
+++ config/application.rb    (working copy)
@@ -64,6 +64,7 @@
     config.log_level = Rails.env.production? ? :info : :debug

     config.session_store :cookie_store, :key => '_redmine_session'
+    config.middleware.use Rack::ContentLength

     if File.exists?(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
       instance_eval File.read(File.join(File.dirname(__FILE__), 'additional_environment.rb'))
Index: config/environments/production.rb
===================================================================
--- config/environments/production.rb    (revision 14625)
+++ config/environments/production.rb    (working copy)
@@ -22,4 +22,6 @@

   # Print deprecation notices to the Rails logger.
   config.active_support.deprecation = :log
+
+  config.action_dispatch.x_sendfile_header = 'X-Sendfile'
 end

Test result:

$ curl --head http://localhost/attachments/download/2/test.txt
HTTP/1.1 200 OK
Date: Wed, 30 Sep 2015 09:54:49 GMT
Server: Apache/2.4.6 (CentOS) Phusion_Passenger/5.0.17
Cache-Control: private
X-XSS-Protection: 1; mode=block
X-Request-Id: 393f7d06-3fbc-4495-9454-53e3b707796f
Content-Disposition: attachment; filename="test.txt" 
Content-Transfer-Encoding: binary
X-Frame-Options: SAMEORIGIN
X-Runtime: 0.014544
X-Content-Type-Options: nosniff
X-Powered-By: Phusion Passenger 5.0.17
Content-Length: 44
ETag: "6cc42dd03abfea586bca741175aee6d4" 
Status: 200 OK
Content-Type: text/plain; charset=UTF-8

Actions #19

Updated by Jean-Philippe Lang about 9 years ago

  • Status changed from New to Closed
  • Assignee set to Jean-Philippe Lang
  • Target version set to 3.2.0
  • Resolution set to Fixed

Rack::ContentLength added in r14632.

Actions

Also available in: Atom PDF