Skip to content

Commit

Permalink
better key_starts_with option handeling
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayne committed Feb 27, 2013
1 parent cb71d75 commit 3227bd0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/s3_direct_upload/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def s3_uploader_form(options = {}, &block)

class S3Uploader
def initialize(options)
@key_starts_with = options[:key_starts_with] || "uploads/"
@options = options.reverse_merge(
aws_access_key_id: S3DirectUpload.config.access_key_id,
aws_secret_access_key: S3DirectUpload.config.secret_access_key,
Expand All @@ -21,7 +22,7 @@ def initialize(options)
expiration: 10.hours.from_now.utc.iso8601,
max_file_size: 500.megabytes,
as: "file",
key_starts_with: "uploads/",
key_starts_with: @key_starts_with,
key: key
)
end
Expand Down Expand Up @@ -53,7 +54,7 @@ def fields
end

def key
@key ||= "uploads/#{DateTime.now.utc.strftime("%Y%m%dT%H%MZ")}_#{SecureRandom.hex}/${filename}"
@key ||= "#{@key_starts_with}#{DateTime.now.utc.strftime("%Y%m%dT%H%MZ")}_#{SecureRandom.hex}/${filename}"
end

def url
Expand Down

0 comments on commit 3227bd0

Please sign in to comment.