mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
proper content-disposition header when downloading attachments
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
class UploadsController < ApplicationController
|
||||
before_filter :ensure_logged_in
|
||||
before_filter :ensure_logged_in, except: [:show]
|
||||
skip_before_filter :check_xhr, only: [:show]
|
||||
|
||||
def create
|
||||
file = params[:file] || params[:files].first
|
||||
@ -28,4 +29,18 @@ class UploadsController < ApplicationController
|
||||
render status: 422, text: I18n.t("upload.images.size_not_found")
|
||||
end
|
||||
|
||||
def show
|
||||
return render nothing: true, status: 404 unless Discourse.store.internal?
|
||||
|
||||
id = params[:id].to_i
|
||||
url = request.fullpath
|
||||
|
||||
# the "url" parameter is here to prevent people from scanning the uploads using the id
|
||||
upload = Upload.where(id: id, url: url).first
|
||||
|
||||
return render nothing: true, status: 404 unless upload
|
||||
|
||||
send_file(Discourse.store.path_for(upload), filename: upload.original_filename)
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user