s3_cors_fileupload 0.1.2 → 0.1.4
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/CHANGELOG.md +9 -0
- data/README.md +16 -3
- data/lib/generators/s3_cors_fileupload/install/install_generator.rb +2 -3
- data/lib/generators/s3_cors_fileupload/install/templates/s3_uploads_controller.rb +0 -36
- data/lib/generators/s3_cors_fileupload/install/templates/views/_template_download.html.erb +1 -1
- data/lib/generators/s3_cors_fileupload/install/templates/views/_template_uploaded.html.erb +1 -1
- data/lib/s3_cors_fileupload/rails/config.rb +2 -1
- data/lib/s3_cors_fileupload/rails/form_helper.rb +3 -3
- data/lib/s3_cors_fileupload/rails/policy_helper.rb +2 -2
- data/lib/s3_cors_fileupload/version.rb +1 -1
- data/s3_cors_fileupload.gemspec +1 -1
- data/vendor/assets/javascripts/s3_cors_fileupload/jquery.fileupload-ui.js +3 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## 0.1.4
|
2
|
+
|
3
|
+
- Added a `data-confirmation` option to the delete buttons and functionality to the jQuery-File-Upload UI's destroy callback that picks up the contents of that attribute to use as a confirmation dialog. (Fixed the implementation from v0.1.3) [See the README notes for more details](https://github.com/fullbridge-batkins/s3_cors_fileupload#notes).
|
4
|
+
|
5
|
+
## 0.1.3 (Yanked)
|
6
|
+
|
7
|
+
- Improving install generator so that generation of the migration file is optional.
|
8
|
+
- Removed some unnecessary code on some of the generator templates.
|
9
|
+
|
1
10
|
## 0.1.2
|
2
11
|
|
3
12
|
- Modified the FormHelper so that view helper method is named `s3_cors_fileupload_form_tag` (instead of `s3_cors_fileupload_form`) to maintain consistency with the rest of ActionView's view helpers.
|
data/README.md
CHANGED
@@ -16,7 +16,12 @@ and views for the file uploading.
|
|
16
16
|
|
17
17
|
bundle exec rails generate s3_cors_fileupload:install
|
18
18
|
|
19
|
-
|
19
|
+
If you don't want to generate a migration (for instance if you've already run the install generator in the past),
|
20
|
+
you can pass in an options `--skip-migration` like so:
|
21
|
+
|
22
|
+
bundle exec rails generate s3_cors_fileupload:install --skip-migration
|
23
|
+
|
24
|
+
If you chose to generate a migration, run it now:
|
20
25
|
|
21
26
|
bundle exec rake db:migrate
|
22
27
|
|
@@ -88,12 +93,12 @@ the UI version of the [jQuery-File-Upload javascript](http://blueimp.github.com/
|
|
88
93
|
This view helper accepts the following options:
|
89
94
|
|
90
95
|
* `:access_key_id` - The AWS Access Key ID of the owner of the bucket. Defaults to the `Config.access_key_id` (read from the `config/amazon_s3.yml` config file).
|
91
|
-
* `:acl` - One of S3's Canned Access Control Lists, must be one of: 'private'
|
96
|
+
* `:acl` - One of S3's Canned Access Control Lists, must be one of: `'private'`, `'public-read'`, `'public-read-write'`, `'authenticated-read'`. Defaults to `'public-read'`.
|
92
97
|
* `:max_file_size` - The max file size (in bytes) that you wish to allow to be uploaded. Defaults to `Config.max_file_size` (read from the `config/amazon_s3.yml` config file) or, if no value is set on the `config/amazon_s3.yml` file, defaults to `524288000` (500 MB)
|
93
98
|
* `:bucket` - The name of the bucket on S3 you wish for the files to be uploaded to. Defaults to `Config.bucket` (read from the `config/amazon_s3.yml` config file).
|
94
99
|
* Any other key creates standard HTML options for the form tag.
|
95
100
|
|
96
|
-
For an example of how to use the helper, see the file located at `app/views/s3_uploads/index.html.erb` that
|
101
|
+
For an example of how to use the form view helper, see the file located at `app/views/s3_uploads/index.html.erb` that
|
97
102
|
the install generator produces.
|
98
103
|
|
99
104
|
## Notes
|
@@ -106,6 +111,14 @@ places throughout your application, you may want look into using a gem such as
|
|
106
111
|
[twitter-bootstrap-rails](https://github.com/seyhunak/twitter-bootstrap-rails), which allows you to inject
|
107
112
|
the stylesheets and javascripts from bootstrap into the asset pipeline.
|
108
113
|
|
114
|
+
I have made a slight modification to the jQuery-File-Upload-UI so that the destroy button accepts an optional `data-confirmation`
|
115
|
+
attribute, which in turn causes it to show a confirmation dialog to the user before the destroy action happens. This functionality
|
116
|
+
mimics that of Rails's built in [jquery-ujs behavior for `data-confirm`](https://github.com/rails/jquery-ujs/wiki/Unobtrusive-scripting-support-for-jQuery)
|
117
|
+
attributes on forms (I named this one `data-confirmation` to prevent jquery-ujs from conflicts).
|
118
|
+
The code for this was based off of [pull request #1127 to the jQuery-File-Upload project](https://github.com/blueimp/jQuery-File-Upload/pull/1127),
|
119
|
+
which appears to have been rejected by the author of jQuery-File-Upload, but seems appropriate for rails. If you wish not to use it,
|
120
|
+
simply remove the `data-confirm` attribute from the destroy button on `_template_uploaded.html.erb` in the views directory.
|
121
|
+
|
109
122
|
## Contributing to S3CorsFileupload
|
110
123
|
|
111
124
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
@@ -9,7 +9,7 @@ module S3CorsFileupload
|
|
9
9
|
extend ActiveRecord::Generators::Migration
|
10
10
|
|
11
11
|
source_root File.expand_path('../templates', __FILE__)
|
12
|
-
|
12
|
+
class_option :migration, :type => :boolean, :default => true, :desc => "Generate a migration for the SourceFile model."
|
13
13
|
|
14
14
|
desc('Creates a config file, then generates (but does not run) a migration to add a source_files table and ' +
|
15
15
|
'a corresponding model, as well as a controller, routes, and views for the file uploading.')
|
@@ -19,7 +19,7 @@ module S3CorsFileupload
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def create_migration_file
|
22
|
-
migration_template 'create_source_files.rb', 'db/migrate/create_source_files.rb'
|
22
|
+
migration_template 'create_source_files.rb', 'db/migrate/create_source_files.rb' if options.migration?
|
23
23
|
end
|
24
24
|
|
25
25
|
def create_model_file
|
@@ -27,7 +27,6 @@ module S3CorsFileupload
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def create_controller
|
30
|
-
# if options.with_controller?
|
31
30
|
copy_file 's3_uploads_controller.rb', 'app/controllers/s3_uploads_controller.rb'
|
32
31
|
copy_file 's3_uploads.js', 'app/assets/javascripts/s3_uploads.js'
|
33
32
|
end
|
@@ -1,11 +1,4 @@
|
|
1
|
-
require 'base64'
|
2
|
-
require 'openssl'
|
3
|
-
require 'digest/sha1'
|
4
|
-
|
5
1
|
class S3UploadsController < ApplicationController
|
6
|
-
|
7
|
-
helper_method :s3_upload_policy_document, :s3_upload_signature
|
8
|
-
|
9
2
|
# GET /source_files
|
10
3
|
# GET /source_files.json
|
11
4
|
def index
|
@@ -58,33 +51,4 @@ class S3UploadsController < ApplicationController
|
|
58
51
|
success_action_redirect: "/"
|
59
52
|
}
|
60
53
|
end
|
61
|
-
|
62
|
-
# ---- Helpers ----
|
63
|
-
# generate the policy document that amazon is expecting.
|
64
|
-
def s3_upload_policy_document
|
65
|
-
Base64.encode64(
|
66
|
-
{
|
67
|
-
expiration: 1.hour.from_now.utc.strftime('%Y-%m-%dT%H:%M:%S.000Z'),
|
68
|
-
conditions: [
|
69
|
-
{ bucket: S3CorsFileupload::Config.bucket },
|
70
|
-
{ acl: 'public-read' },
|
71
|
-
{ success_action_status: '201' },
|
72
|
-
["starts-with", "$key", ""],
|
73
|
-
["starts-with", "$Content-Type", ""]
|
74
|
-
]
|
75
|
-
}.to_json
|
76
|
-
).gsub(/\n|\r/, '')
|
77
|
-
end
|
78
|
-
|
79
|
-
# sign our request by Base64 encoding the policy document.
|
80
|
-
def s3_upload_signature
|
81
|
-
Base64.encode64(
|
82
|
-
OpenSSL::HMAC.digest(
|
83
|
-
OpenSSL::Digest::Digest.new('sha1'),
|
84
|
-
S3CorsFileupload::Config.secret_access_key,
|
85
|
-
s3_upload_policy_document
|
86
|
-
)
|
87
|
-
).gsub(/\n/, '')
|
88
|
-
end
|
89
|
-
|
90
54
|
end
|
@@ -18,7 +18,7 @@
|
|
18
18
|
<td colspan="2"></td>
|
19
19
|
{% } %}
|
20
20
|
<td class="delete">
|
21
|
-
<button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}">
|
21
|
+
<button class="btn btn-danger" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}" data-confirmation="Are you sure?">
|
22
22
|
<i class="icon-trash icon-white"></i>
|
23
23
|
<span>Delete</span>
|
24
24
|
</button>
|
@@ -15,7 +15,7 @@
|
|
15
15
|
<td class="size"><span>{%=formatFileSize(o.size)%}</span></td>
|
16
16
|
<td colspan="2"></td>
|
17
17
|
<td class="delete">
|
18
|
-
<button class="btn btn-danger" data-type="DELETE" data-url="{%=o.delete_url%}">
|
18
|
+
<button class="btn btn-danger" data-type="DELETE" data-url="{%=o.delete_url%}" data-confirmation="Are you sure?">
|
19
19
|
<i class="icon-trash icon-white"></i>
|
20
20
|
<span>Delete</span>
|
21
21
|
</button>
|
@@ -34,13 +34,13 @@ module S3CorsFileupload
|
|
34
34
|
end
|
35
35
|
|
36
36
|
alias_method :s3_cors_fileupload_form, :s3_cors_fileupload_form_tag
|
37
|
-
|
37
|
+
|
38
38
|
private
|
39
|
-
|
39
|
+
|
40
40
|
def build_form_options(options = {})
|
41
41
|
{ :id => 'fileupload' }.merge(options).merge(:multipart => true, :authenticity_token => false)
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
# hidden fields argument should be a hash of key value pairs (values may be blank if desired)
|
45
45
|
def construct_form_html(hidden_fields, bucket, html_options = {}, &block)
|
46
46
|
# now build the html for the form
|
@@ -6,7 +6,7 @@ require 'json'
|
|
6
6
|
module S3CorsFileupload
|
7
7
|
class PolicyHelper
|
8
8
|
attr_reader :options
|
9
|
-
|
9
|
+
|
10
10
|
def initialize(_options = {})
|
11
11
|
# default max_file_size to 500 MB if nothing is received
|
12
12
|
@options = {
|
@@ -15,7 +15,7 @@ module S3CorsFileupload
|
|
15
15
|
:bucket => Config.bucket
|
16
16
|
}.merge(_options).merge(:secret_access_key => Config.secret_access_key)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
# generate the policy document that amazon is expecting.
|
20
20
|
def policy_document
|
21
21
|
Base64.encode64(
|
data/s3_cors_fileupload.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["benatkins@fullbridge.com"]
|
10
10
|
s.homepage = "http://github.com/fullbridge-batkins/s3_cors_fileupload"
|
11
11
|
s.summary = "File uploads for Rails ~> 3.1 to AWS-S3 via CORS using the jQuery-File-Upload script"
|
12
|
-
s.description = "
|
12
|
+
s.description = "Provides file uploads for Rails ~> 3.1 to AWS-S3 via CORS using the jQuery-File-Upload javascript"
|
13
13
|
s.licenses = ["MIT"]
|
14
14
|
|
15
15
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
@@ -293,6 +293,8 @@
|
|
293
293
|
},
|
294
294
|
// Callback for file deletion:
|
295
295
|
destroy: function (e, data) {
|
296
|
+
if (data.confirm && !confirm(data.confirm))
|
297
|
+
return; // abort the deletion if the user rejects the confirmation dialog
|
296
298
|
var that = $(this).data('fileupload');
|
297
299
|
if (data.url) {
|
298
300
|
$.ajax(data);
|
@@ -537,6 +539,7 @@
|
|
537
539
|
context: button.closest('.template-download'),
|
538
540
|
url: button.attr('data-url'),
|
539
541
|
type: button.attr('data-type') || 'DELETE',
|
542
|
+
confirm: button.attr('data-confirmation'),
|
540
543
|
dataType: this.options.dataType
|
541
544
|
});
|
542
545
|
},
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3_cors_fileupload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -91,8 +91,8 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
-
description:
|
95
|
-
|
94
|
+
description: Provides file uploads for Rails ~> 3.1 to AWS-S3 via CORS using the jQuery-File-Upload
|
95
|
+
javascript
|
96
96
|
email:
|
97
97
|
- benatkins@fullbridge.com
|
98
98
|
executables: []
|