Skip to content

Commit

Permalink
add option for content_disposition (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvnill authored and jasdeepsingh committed Sep 19, 2018
1 parent dd096ab commit 32e0e52
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ CarrierWave.configure do |config|
config.gcloud_bucket = 'your-bucket-name'
config.gcloud_bucket_is_public = true
config.gcloud_authenticated_url_expiration = 600
config.gcloud_content_disposition = 'attachment' // or you can skip this
config.gcloud_attributes = {
expires: 600
Expand Down
1 change: 1 addition & 0 deletions lib/carrierwave-google-storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Base
add_config :gcloud_bucket_is_public
add_config :gcloud_credentials
add_config :gcloud_authenticated_url_expiration
add_config :gcloud_content_disposition

configure do |config|
config.storage_engines[:gcloud] = 'CarrierWave::Storage::Gcloud'
Expand Down
7 changes: 5 additions & 2 deletions lib/carrierwave/storage/gcloud_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class GcloudFile
attr_writer :file
attr_accessor :uploader, :connection, :path, :gcloud_options, :file_exists

delegate :content_type, :size, to: :file
delegate :content_disposition, :content_type, :size, to: :file

def initialize(uploader, connection, path)
@uploader = uploader
Expand Down Expand Up @@ -60,7 +60,10 @@ def read
def store(new_file)
new_file_path = uploader.filename ? uploader.filename : new_file.filename
bucket_file = bucket.create_file(
new_file.path, path, content_type: new_file.content_type
new_file.path,
path,
content_type: new_file.content_type,
content_disposition: uploader.gcloud_content_disposition
)
bucket_file.acl.public! if uploader.gcloud_bucket_is_public
self
Expand Down
2 changes: 2 additions & 0 deletions spec/features/storing_files_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def filename

before(:each) do
uploader.gcloud_bucket_is_public = false
uploader.gcloud_content_disposition = 'attachment'
uploader.store!(image)
uploader.retrieve_from_store!('image3.png')
end
Expand All @@ -126,6 +127,7 @@ def filename

expect(uploader.file.content_type).to eq('image/png')
expect(uploader.file.filename).to eq('image3.png')
expect(uploader.file.content_disposition).to eq('attachment')

image.close
uploader.file.delete
Expand Down

0 comments on commit 32e0e52

Please sign in to comment.