s3_direct_upload 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# S3DirectUpload
|
2
2
|
|
3
3
|
Easily generate a form that allows you to upload directly to Amazon S3.
|
4
|
-
Multi file uploading supported by jquery-fileupload.
|
4
|
+
Multi file uploading supported by jquery-fileupload.
|
5
5
|
|
6
6
|
Code extracted from Ryan Bates' [gallery-jquery-fileupload](https://github.com/railscasts/383-uploading-to-amazon-s3/tree/master/gallery-jquery-fileupload).
|
7
7
|
|
@@ -18,6 +18,7 @@ S3DirectUpload.config do |c|
|
|
18
18
|
c.access_key_id = "" # your access key id
|
19
19
|
c.secret_access_key = "" # your secret access key
|
20
20
|
c.bucket = "" # your bucket name
|
21
|
+
c.region = "" # region prefix of your bucket url (optional), eg. "s3-eu-west-1"
|
21
22
|
end
|
22
23
|
```
|
23
24
|
|
@@ -114,11 +115,12 @@ Use the javascript in `s3_direct_upload` as a guide.
|
|
114
115
|
|
115
116
|
## Options for S3Upload jQuery Plugin
|
116
117
|
|
117
|
-
* `path:` manual path for the files on your s3 bucket. Example: `path/to/my/files/on/s3`
|
118
|
+
* `path:` manual path for the files on your s3 bucket. Example: `path/to/my/files/on/s3`
|
118
119
|
Note: the file path in your s3 bucket will effectively be `path + key`.
|
119
|
-
* `additional_data:` You can send additional data to your rails app in the persistence POST request. This would be accessable in your params hash as `params[:key][:value]`
|
120
|
-
Example: `{key: value}`
|
120
|
+
* `additional_data:` You can send additional data to your rails app in the persistence POST request. This would be accessable in your params hash as `params[:key][:value]`
|
121
|
+
Example: `{key: value}`
|
121
122
|
* `remove_completed_progress_bar:` By default, the progress bar will be removed once the file has been successfully uploaded. You can set this to `false` if you want to keep the progress bar.
|
123
|
+
* `remove_failed_progress_bar:` By default, the progress bar will not be removed when uploads fail. You can set this to `true` if you want to remove the progress bar.
|
122
124
|
* `before_add:` Callback function that executes before a file is added to the queue. It is passed file object and expects `true` or `false` to be returned. This could be useful if you would like to validate the filenames of files to be uploaded for example. If true is returned file will be uploaded as normal, false will cancel the upload.
|
123
125
|
|
124
126
|
### Example with all options.
|
@@ -138,7 +140,7 @@ You can change the settings on your form later on by accessing the jQuery instan
|
|
138
140
|
jQuery ->
|
139
141
|
v = $("#myS3Uploader").S3Uploader()
|
140
142
|
...
|
141
|
-
v.path("new/path/")
|
143
|
+
v.path("new/path/")
|
142
144
|
v.additional_data("newdata")
|
143
145
|
```
|
144
146
|
|
@@ -180,6 +182,15 @@ $(document).bind 's3_uploads_complete', ->
|
|
180
182
|
alert("All Uploads completed")
|
181
183
|
```
|
182
184
|
|
185
|
+
#### Rails AJAX Callbacks
|
186
|
+
|
187
|
+
In addition, the regular rails ajax callbacks will trigger on the form with regards to the POST to the server.
|
188
|
+
|
189
|
+
```coffeescript
|
190
|
+
$('#myS3Uploader').bind "ajax:success", (e, data) ->
|
191
|
+
alert("server was notified of new file on S3; responded with '#{data}")
|
192
|
+
```
|
193
|
+
|
183
194
|
## Cleaning old uploads on S3
|
184
195
|
You may be processing the files upon upload and reuploading them to another
|
185
196
|
bucket or directory. If so you can remove the originali files by running a
|
@@ -208,10 +219,10 @@ end
|
|
208
219
|
```
|
209
220
|
|
210
221
|
## Contributing / TODO
|
211
|
-
This is just a simple gem that only really provides some javascript and a form helper.
|
212
|
-
This gem could go all sorts of ways based on what people want and how people contribute.
|
222
|
+
This is just a simple gem that only really provides some javascript and a form helper.
|
223
|
+
This gem could go all sorts of ways based on what people want and how people contribute.
|
213
224
|
Ideas:
|
214
|
-
* More specs!
|
225
|
+
* More specs!
|
215
226
|
* More options to control file types, ability to batch upload.
|
216
227
|
* More convention over configuration on rails side
|
217
228
|
* Create generators.
|
@@ -220,7 +231,7 @@ Ideas:
|
|
220
231
|
|
221
232
|
|
222
233
|
## Credit
|
223
|
-
This gem is basically a small wrapper around code that [Ryan Bates](http://github.com/rbates) wrote for [Railscast#383](http://railscasts.com/episodes/383-uploading-to-amazon-s3). Most of the code in this gem was extracted from [gallery-jquery-fileupload](https://github.com/railscasts/383-uploading-to-amazon-s3/tree/master/gallery-jquery-fileupload).
|
234
|
+
This gem is basically a small wrapper around code that [Ryan Bates](http://github.com/rbates) wrote for [Railscast#383](http://railscasts.com/episodes/383-uploading-to-amazon-s3). Most of the code in this gem was extracted from [gallery-jquery-fileupload](https://github.com/railscasts/383-uploading-to-amazon-s3/tree/master/gallery-jquery-fileupload).
|
224
235
|
|
225
236
|
Thank you Ryan Bates!
|
226
237
|
|
@@ -19,6 +19,7 @@ $.fn.S3Uploader = (options) ->
|
|
19
19
|
additional_data: null
|
20
20
|
before_add: null
|
21
21
|
remove_completed_progress_bar: true
|
22
|
+
remove_failed_progress_bar: false
|
22
23
|
|
23
24
|
$.extend settings, options
|
24
25
|
|
@@ -49,7 +50,17 @@ $.fn.S3Uploader = (options) ->
|
|
49
50
|
to = $uploadForm.data('post')
|
50
51
|
if to
|
51
52
|
content[$uploadForm.data('as')] = content.url
|
52
|
-
|
53
|
+
|
54
|
+
$.ajax
|
55
|
+
type: 'POST'
|
56
|
+
url: to
|
57
|
+
data: content
|
58
|
+
beforeSend: ( xhr, settings ) -> $uploadForm.trigger( 'ajax:beforeSend', [xhr, settings] )
|
59
|
+
complete: ( xhr, status ) -> $uploadForm.trigger( 'ajax:complete', [xhr, status] )
|
60
|
+
success: ( data, status, xhr ) -> $uploadForm.trigger( 'ajax:success', [data, status, xhr] )
|
61
|
+
error: ( xhr, status, error ) -> $uploadForm.trigger( 'ajax:error', [xhr, status, error] )
|
62
|
+
|
63
|
+
# $.post(to, content)
|
53
64
|
|
54
65
|
data.context.remove() if data.context && settings.remove_completed_progress_bar # remove progress bar
|
55
66
|
$uploadForm.trigger("s3_upload_complete", [content])
|
@@ -60,6 +71,8 @@ $.fn.S3Uploader = (options) ->
|
|
60
71
|
fail: (e, data) ->
|
61
72
|
content = build_content_object $uploadForm, data.files[0], data.result
|
62
73
|
content.error_thrown = data.errorThrown
|
74
|
+
|
75
|
+
data.context.remove() if data.context && settings.remove_failed_progress_bar # remove progress bar
|
63
76
|
$uploadForm.trigger("s3_upload_failed", [content])
|
64
77
|
|
65
78
|
formData: (form) ->
|
@@ -15,6 +15,7 @@ module S3DirectUpload
|
|
15
15
|
aws_access_key_id: S3DirectUpload.config.access_key_id,
|
16
16
|
aws_secret_access_key: S3DirectUpload.config.secret_access_key,
|
17
17
|
bucket: S3DirectUpload.config.bucket,
|
18
|
+
region: S3DirectUpload.config.region || "s3",
|
18
19
|
acl: "public-read",
|
19
20
|
expiration: 10.hours.from_now.utc.iso8601,
|
20
21
|
max_file_size: 500.megabytes,
|
@@ -54,7 +55,7 @@ module S3DirectUpload
|
|
54
55
|
end
|
55
56
|
|
56
57
|
def url
|
57
|
-
"https
|
58
|
+
"https://#{@options[:region]}.amazonaws.com/#{@options[:bucket]}/"
|
58
59
|
end
|
59
60
|
|
60
61
|
def policy
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3_direct_upload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
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: 2013-01-
|
12
|
+
date: 2013-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -105,18 +105,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
105
|
- - ! '>='
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
|
-
segments:
|
109
|
-
- 0
|
110
|
-
hash: 4000764443118203735
|
111
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
109
|
none: false
|
113
110
|
requirements:
|
114
111
|
- - ! '>='
|
115
112
|
- !ruby/object:Gem::Version
|
116
113
|
version: '0'
|
117
|
-
segments:
|
118
|
-
- 0
|
119
|
-
hash: 4000764443118203735
|
120
114
|
requirements: []
|
121
115
|
rubyforge_project:
|
122
116
|
rubygems_version: 1.8.23
|