プロジェクト

全般

プロフィール

Vote #75367

完了

Unknown file size while downloading attachment

Admin Redmine さんが4年以上前に追加. 4年以上前に更新.

ステータス:
Closed
優先度:
通常
担当者:
-
カテゴリ:
Attachments_19
対象バージョン:
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
19
version_id:
102
issue_org_id:
17403
author_id:
105975
assigned_to_id:
1
comments:
19
status_id:
5
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
77
ステータス-->[Closed]

説明

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


journals

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.
--------------------------------------------------------------------------------
Just to be sure...

Cast the value to a string.

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

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

Regards,
Amit
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
Tested with 2.4 and 2.5, Content-Length header is properly set in the response.
--------------------------------------------------------------------------------
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:
<pre>
curl -D /tmp/header.txt http://www.redmine.org/attachments/download/11948/Untitled.jpg > /dev/null
</pre>

result:
<pre>
$ 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
</pre>
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
Amit Baswa, you would be better to create a new issue. The resume feature is another topic from this.
--------------------------------------------------------------------------------
Thanks Go MAEDA

--Amit
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
Another solution. Adds Content-Length field if it is not included in a response header.

<pre><code class="diff">
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
</code></pre>
--------------------------------------------------------------------------------
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?
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
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:**
<pre><code class="diff">
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
</code></pre>

**Test result:**
<pre>
$ 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
</pre>
--------------------------------------------------------------------------------
Rack::ContentLength added in r14632.
--------------------------------------------------------------------------------


related_issues

relates,New,17452,Add support for download resume to attachments
relates,Closed,19438,Webrick WARN: "Could not determine content-length of response body"

Admin Redmine さんが4年以上前に更新

  • カテゴリAttachments_19 にセット
  • 対象バージョン3.2.0_102 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0