qoobaa-s3_upload_form 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +22 -5
- data/VERSION +1 -1
- data/lib/s3_upload_form/helpers.rb +10 -10
- data/s3_upload_form.gemspec +3 -3
- metadata +4 -3
data/README.markdown
CHANGED
@@ -1,11 +1,28 @@
|
|
1
1
|
# s3_upload_form
|
2
2
|
|
3
3
|
### Usage
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
<% form_tag s3_bucket_url, :multipart => true do -%>
|
5
|
+
<%= s3_signature_tag :key => "uploads",
|
6
|
+
:redirect => image_processing_url,
|
7
|
+
:acl => "public-read",
|
8
|
+
:max_filesize => 0..5.megabytes,
|
9
|
+
:submit => submit_tag("Upload!") %>
|
10
|
+
<%= label_tag :file, "File" %>
|
11
|
+
<br/>
|
12
|
+
<%= file_field_tag :file %>
|
13
|
+
<br/>
|
14
|
+
<%= submit_tag "Upload" %>
|
15
|
+
<% end -%>
|
16
|
+
|
17
|
+
Remember to turn off the request forgery protection in the controller:
|
18
|
+
|
19
|
+
class UploadsController < ApplicationController
|
20
|
+
self.allow_forgery_protection = false
|
21
|
+
|
22
|
+
def new
|
23
|
+
# ...
|
24
|
+
end
|
25
|
+
end
|
9
26
|
|
10
27
|
### Configuration
|
11
28
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -1,20 +1,26 @@
|
|
1
1
|
module S3UploadForm
|
2
2
|
module Helpers
|
3
|
-
def
|
3
|
+
def s3_bucket_url(protocol = "http")
|
4
|
+
bucket = S3UploadForm.configuration.bucket
|
5
|
+
|
6
|
+
raise "Please configure S3UploadForm before use" if bucket.blank?
|
7
|
+
|
8
|
+
"#{protocol}://#{bucket}.s3.amazonaws.com/"
|
9
|
+
end
|
10
|
+
|
11
|
+
def s3_signature_tag(options = {})
|
4
12
|
bucket = S3UploadForm.configuration.bucket
|
5
13
|
access_key_id = S3UploadForm.configuration.access_key_id
|
6
14
|
secret_access_key = S3UploadForm.configuration.secret_access_key
|
7
15
|
|
8
16
|
raise "Please configure S3UploadForm before use" if bucket.blank? or access_key_id.blank? or secret_access_key.blank?
|
9
17
|
|
10
|
-
protocol = options.delete(:protocol) || "http"
|
11
18
|
key = options.delete(:key) || ""
|
12
19
|
redirect = options.delete(:redirect) || "/"
|
13
20
|
acl = options.delete(:acl) || "public-read"
|
14
21
|
expiration_date = (options.delete(:expiration_date) || 10.hours).from_now.strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
15
22
|
filesize = options.delete(:filesize) || (1..1.megabyte)
|
16
23
|
filesize_range = filesize.kind_of?(Fixnum) ? 1..filesize : filesize
|
17
|
-
submit = options.delete(:submit) || submit_tag(I18n.t("button.upload", :default => "Upload"))
|
18
24
|
|
19
25
|
policy_document = <<-eos
|
20
26
|
{
|
@@ -33,11 +39,7 @@ module S3UploadForm
|
|
33
39
|
policy = Base64.encode64(policy_document).gsub("\n","")
|
34
40
|
signature = Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new("sha1"), secret_access_key, policy)).gsub("\n","")
|
35
41
|
|
36
|
-
|
37
|
-
options[:method] ||= "post"
|
38
|
-
options[:enctype] ||= "multipart/form-data"
|
39
|
-
|
40
|
-
content_tag :form, options do
|
42
|
+
content_tag :div, :style => "margin: 0pt; padding: 0pt; display: inline;" do
|
41
43
|
content = ""
|
42
44
|
content << hidden_field_tag("key", "#{key}/${filename}")
|
43
45
|
content << hidden_field_tag("AWSAccessKeyId", access_key_id)
|
@@ -45,8 +47,6 @@ module S3UploadForm
|
|
45
47
|
content << hidden_field_tag("success_action_redirect", redirect)
|
46
48
|
content << hidden_field_tag("policy", policy)
|
47
49
|
content << hidden_field_tag("signature", signature)
|
48
|
-
content << file_field_tag("file")
|
49
|
-
content << submit
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
data/s3_upload_form.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{s3_upload_form}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.3.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Jakub Kuźma"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-08-03}
|
10
10
|
s.email = %q{qoobaa@gmail.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
s.homepage = %q{http://github.com/qoobaa/s3_upload_form}
|
31
31
|
s.rdoc_options = ["--charset=UTF-8"]
|
32
32
|
s.require_paths = ["lib"]
|
33
|
-
s.rubygems_version = %q{1.3.
|
33
|
+
s.rubygems_version = %q{1.3.5}
|
34
34
|
s.summary = %q{S3 file upload form}
|
35
35
|
s.test_files = [
|
36
36
|
"test/test_helper.rb"
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Jakub Ku\xC5\xBAma"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-03 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- test/test_helper.rb
|
39
39
|
has_rdoc: false
|
40
40
|
homepage: http://github.com/qoobaa/s3_upload_form
|
41
|
+
licenses:
|
41
42
|
post_install_message:
|
42
43
|
rdoc_options:
|
43
44
|
- --charset=UTF-8
|
@@ -58,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
59
|
requirements: []
|
59
60
|
|
60
61
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.
|
62
|
+
rubygems_version: 1.3.5
|
62
63
|
signing_key:
|
63
64
|
specification_version: 3
|
64
65
|
summary: S3 file upload form
|