Skip to content

Commit

Permalink
Merge pull request #24 from sadfuzzy/master
Browse files Browse the repository at this point in the history
Add support for placing files in folders.
  • Loading branch information
ka8725 committed Nov 24, 2014
2 parents 4710489 + 1ceab01 commit d56d1e3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
3 changes: 2 additions & 1 deletion plugins/redmine_s3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This [Redmine](http://www.redmine.org) plugin makes file attachments be stored o
4. Edit config/s3.yml with your favourite editor
5. Restart mongrel/upload to production/whatever
6. *Optional*: Run `rake redmine_s3:files_to_s3` to upload files in your files folder to s3
7. `rm -Rf plugins/redmine_s3/.git`
7. `rm -Rf plugins/redmine_s3/.git`

## Options Overview
* The bucket specified in s3.yml will be created automatically when the plugin is loaded (this is generally when the server starts).
Expand All @@ -25,6 +25,7 @@ This [Redmine](http://www.redmine.org) plugin makes file attachments be stored o
* access_key_id: string key (required)
* secret_access_key: string key (required)
* bucket: string bucket name (required)
* folder: string folder name inside bucket (for example: 'attachments')
* endpoint: string endpoint instead of s3.amazonaws.com
* secure: boolean true/false
* private: boolean true/false
Expand Down
24 changes: 16 additions & 8 deletions plugins/redmine_s3/config/s3.yml.example
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
production:
access_key_id:
secret_access_key:
bucket:
access_key_id:
secret_access_key:
bucket:
folder:
endpoint:
secure:
private:
expires:
expires:
proxy:

development:
access_key_id:
secret_access_key:
bucket:
access_key_id:
secret_access_key:
bucket:
folder:
endpoint:
secure:
private:
expires:
expires:
proxy:

# Uncomment this to run plugin tests with standart redmine script
# test:
# access_key_id:
# secret_access_key:
# bucket:
14 changes: 12 additions & 2 deletions plugins/redmine_s3/lib/redmine_s3/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Connection
:access_key_id => nil,
:secret_access_key => nil,
:bucket => nil,
:folder => '',
:endpoint => nil,
:private => false,
:expires => nil,
Expand All @@ -20,7 +21,7 @@ class << self
def load_options
file = ERB.new( File.read(File.join(Rails.root, 'config', 's3.yml')) ).result
YAML::load( file )[Rails.env].each do |key, value|
@@s3_options[key.to_sym] = value
@@s3_options[key.to_sym] = value
end
end

Expand Down Expand Up @@ -48,6 +49,15 @@ def create_bucket
self.conn.buckets.create(self.bucket) unless bucket.exists?
end

def folder
str = @@s3_options[:folder]
if str.present?
str.match(/\S+\//) ? str : "#{str}/"
else
''
end
end

def endpoint
@@s3_options[:endpoint]
end
Expand All @@ -70,7 +80,7 @@ def proxy?

def object(filename)
bucket = self.conn.buckets[self.bucket]
bucket.objects[filename]
bucket.objects[folder + filename]
end

def put(filename, data, content_type='application/octet-stream')
Expand Down

0 comments on commit d56d1e3

Please sign in to comment.