post_to_s3 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +2 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/lib/post_to_s3/file_upload.rb +46 -0
- data/lib/post_to_s3/version.rb +3 -0
- data/lib/post_to_s3/view_helpers.rb +30 -0
- data/lib/post_to_s3.rb +30 -0
- data/post_to_s3.gemspec +22 -0
- metadata +104 -0
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# PostToS3
|
2
|
+
|
3
|
+
A configuration and setup helper for using direct to S3 form uploads. Basically just an extraction of the ViewHelper and FormUpload pieces from Ungluate ( http://github.com/camelpunch/ungulate )
|
4
|
+
|
5
|
+
# License
|
6
|
+
|
7
|
+
file_upload.rb, view_helpers.rb and much of post_to_s3.rb are subject to the following license:
|
8
|
+
|
9
|
+
Copyright (c) 2010 Camel Punch Limited
|
10
|
+
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
12
|
+
a copy of this software and associated documentation files (the
|
13
|
+
"Software"), to deal in the Software without restriction, including
|
14
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
15
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
16
|
+
permit persons to whom the Software is furnished to do so, subject to
|
17
|
+
the following conditions:
|
18
|
+
|
19
|
+
The above copyright notice and this permission notice shall be
|
20
|
+
included in all copies or substantial portions of the Software.
|
21
|
+
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
23
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
24
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
25
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
26
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
27
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
28
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
29
|
+
|
30
|
+
-----------
|
31
|
+
|
32
|
+
The remainder is Copyright (c) 2012 Jeremy Hubert, release under the MIT License
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'active_support/core_ext/class/attribute_accessors'
|
2
|
+
require 'active_support/json'
|
3
|
+
module PostToS3
|
4
|
+
class FileUpload
|
5
|
+
attr_reader(:acl, :bucket_url, :conditions,
|
6
|
+
:key, :policy, :success_action_redirect)
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@bucket_url = options[:bucket_url]
|
10
|
+
@key = options[:key]
|
11
|
+
@policy = options[:policy]
|
12
|
+
|
13
|
+
if @policy
|
14
|
+
@policy['expiration'] = @policy['expiration'].utc
|
15
|
+
|
16
|
+
@conditions =
|
17
|
+
@policy['conditions'].map {|condition| condition.to_a.flatten }
|
18
|
+
|
19
|
+
@acl, @success_action_redirect =
|
20
|
+
Hash[@conditions].values_at('acl', 'success_action_redirect')
|
21
|
+
|
22
|
+
@policy =
|
23
|
+
Base64.encode64(ActiveSupport::JSON.encode(@policy)).gsub("\n", '')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def access_key_id
|
28
|
+
config.access_key_id
|
29
|
+
end
|
30
|
+
|
31
|
+
def signature
|
32
|
+
Base64.encode64(
|
33
|
+
OpenSSL::HMAC.digest(
|
34
|
+
OpenSSL::Digest::Digest.new('sha1'),
|
35
|
+
config.secret_access_key,
|
36
|
+
policy
|
37
|
+
)).gsub("\n", '')
|
38
|
+
end
|
39
|
+
|
40
|
+
protected
|
41
|
+
|
42
|
+
def config
|
43
|
+
PostToS3.configuration
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module PostToS3
|
2
|
+
module ViewHelpers
|
3
|
+
def s3_upload_form_for(upload, &block)
|
4
|
+
open_form = <<HTML
|
5
|
+
<form action="#{upload.bucket_url}" enctype="multipart/form-data" method="post">
|
6
|
+
<div>
|
7
|
+
<input name="key" type="hidden" value="#{upload.key}" />
|
8
|
+
<input name="AWSAccessKeyId" type="hidden" value="#{upload.access_key_id}" />
|
9
|
+
<input name="acl" type="hidden" value="#{upload.acl}" />
|
10
|
+
<input name="policy" type="hidden" value="#{upload.policy}" />
|
11
|
+
<input name="signature" type="hidden" value="#{upload.signature}" />
|
12
|
+
<input name="success_action_redirect" type="hidden" value="#{upload.success_action_redirect}" />
|
13
|
+
HTML
|
14
|
+
|
15
|
+
close_form = "\n</div>\n</form>\n"
|
16
|
+
|
17
|
+
if respond_to?(:safe_concat)
|
18
|
+
content = capture(&block)
|
19
|
+
output = ActiveSupport::SafeBuffer.new
|
20
|
+
output.safe_concat(open_form.html_safe)
|
21
|
+
output << content
|
22
|
+
output.safe_concat(close_form.html_safe)
|
23
|
+
else
|
24
|
+
concat(open_form)
|
25
|
+
yield
|
26
|
+
concat(close_form)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/post_to_s3.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
|
3
|
+
require 'hashie'
|
4
|
+
|
5
|
+
module PostToS3
|
6
|
+
class Configuration < Hashie::Mash; end
|
7
|
+
class MissingConfiguration < StandardError; end
|
8
|
+
|
9
|
+
def self.configuration
|
10
|
+
@config ||=
|
11
|
+
begin
|
12
|
+
config = Configuration.new
|
13
|
+
|
14
|
+
# default creds to those in ENV
|
15
|
+
config.access_key_id = ENV['AMAZON_ACCESS_KEY_ID']
|
16
|
+
config.secret_access_key = ENV['AMAZON_SECRET_ACCESS_KEY']
|
17
|
+
|
18
|
+
config
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.configure(&block)
|
23
|
+
yield configuration
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if defined? ActionView::Base
|
28
|
+
require 'post_to_s3/view_helpers'
|
29
|
+
ActionView::Base.send :include, PostToS3::ViewHelpers
|
30
|
+
end
|
data/post_to_s3.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "post_to_s3/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "post_to_s3"
|
7
|
+
s.version = PostToS3::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jeremy Hubert"]
|
10
|
+
s.email = ["jhubert@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/jhubert/post-to-s3"
|
12
|
+
s.summary = %q{A simple gem for uploading files directly to s3 via a POST command}
|
13
|
+
s.description = %q{A simple gem for uploading files directly to s3 via a POST command}
|
14
|
+
|
15
|
+
s.rubyforge_project = "post-to-s3"
|
16
|
+
|
17
|
+
s.add_runtime_dependency('activesupport', [">= 2.3.5"])
|
18
|
+
s.add_runtime_dependency('hashie', [">= 1.2.0"])
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: post_to_s3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jeremy Hubert
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-01-23 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activesupport
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 9
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 3
|
32
|
+
- 5
|
33
|
+
version: 2.3.5
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: hashie
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 31
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 2
|
48
|
+
- 0
|
49
|
+
version: 1.2.0
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
description: A simple gem for uploading files directly to s3 via a POST command
|
53
|
+
email:
|
54
|
+
- jhubert@gmail.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- Gemfile
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- lib/post_to_s3.rb
|
66
|
+
- lib/post_to_s3/file_upload.rb
|
67
|
+
- lib/post_to_s3/version.rb
|
68
|
+
- lib/post_to_s3/view_helpers.rb
|
69
|
+
- post_to_s3.gemspec
|
70
|
+
homepage: http://github.com/jhubert/post-to-s3
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project: post-to-s3
|
99
|
+
rubygems_version: 1.8.15
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: A simple gem for uploading files directly to s3 via a POST command
|
103
|
+
test_files: []
|
104
|
+
|