Defect #17403
closedUnknown file size while downloading attachment
0%
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
Related issues
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.
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
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
Updated by Amit Baswa over 10 years ago
- File Untitled.png Untitled.png added
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
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
Updated by Amit Baswa over 10 years ago
- File Untitled.jpg Untitled.jpg added
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
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.
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
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
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.
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.
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
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?
Updated by Toshi MARUYAMA about 10 years ago
- Related to Feature #17452: Add support for download resume to attachments added
Updated by Toshi MARUYAMA about 10 years ago
- Resolution deleted (
Cant reproduce)
Updated by Toshi MARUYAMA over 9 years ago
- Related to Defect #19438: Webrick WARN: "Could not determine content-length of response body" added
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
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.