Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
9e024668
Commit
9e024668
authored
May 15, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Files controller handle redirect to remote storage. Added config block to carrierwave init
parent
ced044ad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
18 deletions
+24
-18
app/controllers/files_controller.rb
app/controllers/files_controller.rb
+8
-4
app/uploaders/attachment_uploader.rb
app/uploaders/attachment_uploader.rb
+5
-5
config/initializers/carrierwave.rb
config/initializers/carrierwave.rb
+11
-9
No files found.
app/controllers/files_controller.rb
View file @
9e024668
class
FilesController
<
ApplicationController
class
FilesController
<
ApplicationController
def
download
def
download
note
=
Note
.
find
(
params
[
:id
])
note
=
Note
.
find
(
params
[
:id
])
uploader
=
note
.
attachment
if
can?
(
current_user
,
:read_project
,
note
.
project
)
if
uploader
.
file_storage?
uploader
=
note
.
attachment
if
can?
(
current_user
,
:read_project
,
note
.
project
)
send_file
uploader
.
file
.
path
,
disposition:
'attachment'
send_file
uploader
.
file
.
path
,
disposition:
'attachment'
else
not_found!
end
else
else
not_found!
redirect_to
uploader
.
url
end
end
end
end
end
end
...
...
app/uploaders/attachment_uploader.rb
View file @
9e024668
...
@@ -21,10 +21,10 @@ class AttachmentUploader < CarrierWave::Uploader::Base
...
@@ -21,10 +21,10 @@ class AttachmentUploader < CarrierWave::Uploader::Base
end
end
def
secure_url
def
secure_url
if
self
.
class
.
storage
==
CarrierWave
::
Storage
::
File
"/files/
#{
model
.
class
.
to_s
.
underscore
}
/
#{
model
.
id
}
/
#{
file
.
filename
}
"
"/files/
#{
model
.
class
.
to_s
.
underscore
}
/
#{
model
.
id
}
/
#{
file
.
filename
}
"
end
else
url
def
file_storage?
end
self
.
class
.
storage
==
CarrierWave
::
Storage
::
File
end
end
end
end
config/initializers/carrierwave.rb
View file @
9e024668
...
@@ -5,13 +5,15 @@ aws_file = Rails.root.join('config', 'aws.yml')
...
@@ -5,13 +5,15 @@ aws_file = Rails.root.join('config', 'aws.yml')
if
File
.
exists?
(
aws_file
)
if
File
.
exists?
(
aws_file
)
AWS_CONFIG
=
YAML
.
load
(
File
.
read
(
aws_file
))[
Rails
.
env
]
AWS_CONFIG
=
YAML
.
load
(
File
.
read
(
aws_file
))[
Rails
.
env
]
config
.
fog_credentials
=
{
CarrierWave
.
configure
do
|
config
|
provider:
'AWS'
,
# required
config
.
fog_credentials
=
{
aws_access_key_id:
AWS_CONFIG
[
'access_key_id'
],
# required
provider:
'AWS'
,
# required
aws_secret_access_key:
AWS_CONFIG
[
'secret_access_key'
],
# required
aws_access_key_id:
AWS_CONFIG
[
'access_key_id'
],
# required
region:
AWS_CONFIG
[
'region'
],
# optional, defaults to 'us-east-1'
aws_secret_access_key:
AWS_CONFIG
[
'secret_access_key'
],
# required
}
region:
AWS_CONFIG
[
'region'
],
# optional, defaults to 'us-east-1'
config
.
fog_directory
=
AWS_CONFIG
[
'bucket'
]
# required
}
config
.
fog_public
=
false
# optional, defaults to true
config
.
fog_directory
=
AWS_CONFIG
[
'bucket'
]
# required
config
.
fog_attributes
=
{
'Cache-Control'
=>
'max-age=315576000'
}
# optional, defaults to {}
config
.
fog_public
=
false
# optional, defaults to true
config
.
fog_attributes
=
{
'Cache-Control'
=>
'max-age=315576000'
}
# optional, defaults to {}
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment