qoobaa-s3_upload_form 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +5 -5
- data/VERSION +1 -1
- data/generators/s3_upload_form/s3_upload_form_generator.rb +17 -0
- data/generators/s3_upload_form/templates/initializers/s3_upload_form.rb +5 -0
- data/lib/s3_upload_form/configuration.rb +18 -0
- data/lib/s3_upload_form/helpers.rb +53 -0
- data/lib/s3_upload_form.rb +8 -0
- data/s3_upload_form.gemspec +48 -0
- metadata +7 -1
data/README.markdown
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
#
|
1
|
+
# s3_upload_form
|
2
2
|
|
3
3
|
### Usage
|
4
4
|
<%= s3_upload_form_tag :key => 'uploads',
|
5
5
|
:redirect => image_processing_url,
|
6
6
|
:acl => 'public-read',
|
7
|
-
:max_filesize => 5.megabytes,
|
8
|
-
:
|
7
|
+
:max_filesize => 0..5.megabytes,
|
8
|
+
:submit => submit_tag("Upload!") %>
|
9
9
|
|
10
10
|
### Configuration
|
11
11
|
|
12
12
|
To configure s3_upload_form use s3_upload_form generator...
|
13
|
-
|
13
|
+
./script/generate s3_upload_form
|
14
14
|
|
15
15
|
... and edit the generated initializer file s3_upload_form.rb.
|
16
16
|
|
17
|
-
|
17
|
+
### Jakub Kuźma, 2009
|
18
18
|
|
19
19
|
The gem is based on D2S3 plugin by Matthew Williams.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
class S3UploadFormGenerator < Rails::Generator::Base
|
4
|
+
def manifest
|
5
|
+
record do |m|
|
6
|
+
m.directory "config"
|
7
|
+
m.directory "config/initializers"
|
8
|
+
m.file "initializers/s3_upload_form.rb", "config/initializers/s3_upload_form.rb"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def banner
|
15
|
+
"Usage: #{$0} s3_upload_form"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "singleton"
|
2
|
+
|
3
|
+
module S3UploadForm
|
4
|
+
class Configuration
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
ATTRIBUTES = [:access_key_id, :secret_access_key, :bucket]
|
8
|
+
|
9
|
+
attr_accessor *ATTRIBUTES
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.configuration
|
13
|
+
if block_given?
|
14
|
+
yield Configuration.instance
|
15
|
+
end
|
16
|
+
Configuration.instance
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module S3UploadForm
|
2
|
+
module Helpers
|
3
|
+
def s3_upload_form_tag(options = {})
|
4
|
+
bucket = S3UploadForm.configuration.bucket
|
5
|
+
access_key_id = S3UploadForm.configuration.access_key_id
|
6
|
+
secret_access_key = S3UploadForm.configuration.secret_access_key
|
7
|
+
|
8
|
+
raise "Please configure S3UploadForm before use" if bucket.blank? or access_key_id.blank? or secret_access_key.blank?
|
9
|
+
|
10
|
+
protocol = options.delete(:protocol) || "http"
|
11
|
+
key = options.delete(:key) || ""
|
12
|
+
redirect = options.delete(:redirect) || "/"
|
13
|
+
acl = options.delete(:acl) || "public-read"
|
14
|
+
expiration_date = (options.delete(:expiration_date) || 10.hours).from_now.strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
15
|
+
filesize = options.delete(:filesize) || 0..1.megabyte
|
16
|
+
filesize = 0..filesize if filesize.kind_of?(Fixnum)
|
17
|
+
submit = options.delete(:submit_button) || submit_tag(I18n.t("button.upload", :default => "Upload"))
|
18
|
+
|
19
|
+
policy_document = <<-eos
|
20
|
+
{
|
21
|
+
"expiration": "#{expiration_date}",
|
22
|
+
"conditions":
|
23
|
+
[
|
24
|
+
{"bucket": "#{bucket}"},
|
25
|
+
["starts-with", "$key", "#{key}"],
|
26
|
+
{"acl": "#{acl}"},
|
27
|
+
{"success_action_redirect": "#{redirect}"},
|
28
|
+
["content-length-range", #{filesize.first}, #{filesize.last}]
|
29
|
+
]
|
30
|
+
}
|
31
|
+
eos
|
32
|
+
|
33
|
+
policy = Base64.encode64(policy_document).gsub("\n","")
|
34
|
+
signature = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new("sha1"), secret_access_key, policy)).gsub("\n","")
|
35
|
+
|
36
|
+
options[:action] ||= "#{protocol}://#{bucket}.s3.amazonaws.com/"
|
37
|
+
options[:method] ||= "post"
|
38
|
+
options[:enctype] ||= "multipart/form-data"
|
39
|
+
|
40
|
+
content_tag :form, options do
|
41
|
+
content = ""
|
42
|
+
content << hidden_field_tag("key", "#{key}/${filename}")
|
43
|
+
content << hidden_field_tag("AWSAccessKeyId", access_key_id)
|
44
|
+
content << hidden_field_tag("acl", acl)
|
45
|
+
content << hidden_field_tag("success_action_redirect", redirect)
|
46
|
+
content << hidden_field_tag("policy", policy)
|
47
|
+
content << hidden_field_tag("signature", signature)
|
48
|
+
content << file_field_tag("file")
|
49
|
+
content << submit
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{s3_upload_form}
|
5
|
+
s.version = "0.2.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Jakub Kuźma"]
|
9
|
+
s.date = %q{2009-06-16}
|
10
|
+
s.email = %q{qoobaa@gmail.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.markdown"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.markdown",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"generators/s3_upload_form/s3_upload_form_generator.rb",
|
23
|
+
"generators/s3_upload_form/templates/initializers/s3_upload_form.rb",
|
24
|
+
"lib/s3_upload_form.rb",
|
25
|
+
"lib/s3_upload_form/configuration.rb",
|
26
|
+
"lib/s3_upload_form/helpers.rb",
|
27
|
+
"s3_upload_form.gemspec",
|
28
|
+
"test/test_helper.rb"
|
29
|
+
]
|
30
|
+
s.homepage = %q{http://github.com/qoobaa/s3_upload_form}
|
31
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
32
|
+
s.require_paths = ["lib"]
|
33
|
+
s.rubygems_version = %q{1.3.4}
|
34
|
+
s.summary = %q{S3 file upload form}
|
35
|
+
s.test_files = [
|
36
|
+
"test/test_helper.rb"
|
37
|
+
]
|
38
|
+
|
39
|
+
if s.respond_to? :specification_version then
|
40
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
44
|
+
else
|
45
|
+
end
|
46
|
+
else
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qoobaa-s3_upload_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jakub Ku\xC5\xBAma"
|
@@ -29,6 +29,12 @@ files:
|
|
29
29
|
- README.markdown
|
30
30
|
- Rakefile
|
31
31
|
- VERSION
|
32
|
+
- generators/s3_upload_form/s3_upload_form_generator.rb
|
33
|
+
- generators/s3_upload_form/templates/initializers/s3_upload_form.rb
|
34
|
+
- lib/s3_upload_form.rb
|
35
|
+
- lib/s3_upload_form/configuration.rb
|
36
|
+
- lib/s3_upload_form/helpers.rb
|
37
|
+
- s3_upload_form.gemspec
|
32
38
|
- test/test_helper.rb
|
33
39
|
has_rdoc: false
|
34
40
|
homepage: http://github.com/qoobaa/s3_upload_form
|