s3_swf_upload 0.3.2
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/.gitignore +6 -0
- data/CHANGELOG +26 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/Manifest +34 -0
- data/README.textile +223 -0
- data/Rakefile +14 -0
- data/flex_src/bin-release/flex-config.xml +361 -0
- data/flex_src/compile +2 -0
- data/flex_src/src/Globals.as +15 -0
- data/flex_src/src/S3Uploader.as +204 -0
- data/flex_src/src/com/adobe/net/MimeTypeMap.as +196 -0
- data/flex_src/src/com/elctech/S3UploadOptions.as +32 -0
- data/flex_src/src/com/elctech/S3UploadRequest.as +259 -0
- data/flex_src/src/com/nathancolgate/s3_swf_upload/BrowseButton.as +55 -0
- data/flex_src/src/com/nathancolgate/s3_swf_upload/S3Queue.as +117 -0
- data/flex_src/src/com/nathancolgate/s3_swf_upload/S3Signature.as +118 -0
- data/flex_src/src/com/nathancolgate/s3_swf_upload/S3Upload.as +111 -0
- data/lib/patch/integer.rb +12 -0
- data/lib/s3_swf_upload/railtie.rb +16 -0
- data/lib/s3_swf_upload/railties/generators/s3_swf_upload.rb +19 -0
- data/lib/s3_swf_upload/railties/generators/uploader/USAGE +10 -0
- data/lib/s3_swf_upload/railties/generators/uploader/templates/amazon_s3.yml +20 -0
- data/lib/s3_swf_upload/railties/generators/uploader/templates/s3_down_button.gif +0 -0
- data/lib/s3_swf_upload/railties/generators/uploader/templates/s3_over_button.gif +0 -0
- data/lib/s3_swf_upload/railties/generators/uploader/templates/s3_up_button.gif +0 -0
- data/lib/s3_swf_upload/railties/generators/uploader/templates/s3_upload.js +118 -0
- data/lib/s3_swf_upload/railties/generators/uploader/templates/s3_upload.swf +0 -0
- data/lib/s3_swf_upload/railties/generators/uploader/templates/s3_uploads_controller.rb +53 -0
- data/lib/s3_swf_upload/railties/generators/uploader/uploader_generator.rb +20 -0
- data/lib/s3_swf_upload/railties/tasks/crossdomain.xml +5 -0
- data/lib/s3_swf_upload/s3_config.rb +43 -0
- data/lib/s3_swf_upload/signature.rb +203 -0
- data/lib/s3_swf_upload/view_helpers.rb +171 -0
- data/lib/s3_swf_upload.rb +10 -0
- data/s3_swf_upload.gemspec +29 -0
- metadata +103 -0
data/.gitignore
ADDED
data/CHANGELOG
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
v0.3.1
|
2
|
+
|
3
|
+
* 2010-11-15
|
4
|
+
* Fixed by yixster: If the startUploading call is made after calling stopUploading, only the first file in the queue is successfully uploaded.
|
5
|
+
|
6
|
+
v0.3.0
|
7
|
+
|
8
|
+
* 2010-08-27
|
9
|
+
* Flash Player 10.1 did not allow ExternalInterface to pass a FileReference object to Javascript
|
10
|
+
So I added a toJavascript function that converts FileReference into simple Objects with only three attributes:
|
11
|
+
- name
|
12
|
+
- size
|
13
|
+
- type
|
14
|
+
* Also, S3Queue now has it's own toJavascript function. The queue that gets passed through to the Javascript now
|
15
|
+
has a much more meaningful attribute of 'files' instead of 'source'
|
16
|
+
|
17
|
+
v0.2.0
|
18
|
+
|
19
|
+
* 2010-05-27
|
20
|
+
* The flex application in this fork was completely re-written so that there are no flash or flex UI components.
|
21
|
+
The one exception to that is the browse button, which, for security purposes MUST be flash.
|
22
|
+
But even then, you get to pass the URLs for images to use for that button!
|
23
|
+
|
24
|
+
v0.1.0
|
25
|
+
|
26
|
+
* Created by people way smarter than I
|
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
CHANGELOG
|
2
|
+
MIT-LICENSE
|
3
|
+
Manifest
|
4
|
+
README.textile
|
5
|
+
Rakefile
|
6
|
+
flex_src/bin-release/flex-config.xml
|
7
|
+
flex_src/compile
|
8
|
+
flex_src/src/Globals.as
|
9
|
+
flex_src/src/S3Uploader.as
|
10
|
+
flex_src/src/com/adobe/net/MimeTypeMap.as
|
11
|
+
flex_src/src/com/elctech/S3UploadOptions.as
|
12
|
+
flex_src/src/com/elctech/S3UploadRequest.as
|
13
|
+
flex_src/src/com/nathancolgate/s3_swf_upload/BrowseButton.as
|
14
|
+
flex_src/src/com/nathancolgate/s3_swf_upload/S3Queue.as
|
15
|
+
flex_src/src/com/nathancolgate/s3_swf_upload/S3Signature.as
|
16
|
+
flex_src/src/com/nathancolgate/s3_swf_upload/S3Upload.as
|
17
|
+
lib/patch/integer.rb
|
18
|
+
lib/s3_swf_upload.rb
|
19
|
+
lib/s3_swf_upload/railtie.rb
|
20
|
+
lib/s3_swf_upload/railties/generators/s3_swf_upload.rb
|
21
|
+
lib/s3_swf_upload/railties/generators/uploader/USAGE
|
22
|
+
lib/s3_swf_upload/railties/generators/uploader/templates/amazon_s3.yml
|
23
|
+
lib/s3_swf_upload/railties/generators/uploader/templates/s3_down_button.gif
|
24
|
+
lib/s3_swf_upload/railties/generators/uploader/templates/s3_over_button.gif
|
25
|
+
lib/s3_swf_upload/railties/generators/uploader/templates/s3_up_button.gif
|
26
|
+
lib/s3_swf_upload/railties/generators/uploader/templates/s3_upload.js
|
27
|
+
lib/s3_swf_upload/railties/generators/uploader/templates/s3_upload.swf
|
28
|
+
lib/s3_swf_upload/railties/generators/uploader/templates/s3_uploads_controller.rb
|
29
|
+
lib/s3_swf_upload/railties/generators/uploader/uploader_generator.rb
|
30
|
+
lib/s3_swf_upload/railties/tasks/crossdomain.xml
|
31
|
+
lib/s3_swf_upload/s3_config.rb
|
32
|
+
lib/s3_swf_upload/signature.rb
|
33
|
+
lib/s3_swf_upload/view_helpers.rb
|
34
|
+
s3_swf_upload.gemspec
|
data/README.textile
ADDED
@@ -0,0 +1,223 @@
|
|
1
|
+
h1. S3SwfUpload Gem For Rails 3
|
2
|
+
|
3
|
+
S3SwfUpload allows user to upload a file to S3 directly, so you can save the cost of uploading process in your app server.
|
4
|
+
|
5
|
+
The flex application in this fork was completely re-written so that there are no flash or flex UI components. The one exception to that is the browse button, which, for security purposes MUST be flash. But even then, you get to pass the URLs for images to use for that button!
|
6
|
+
|
7
|
+
The goal of this re-write is to put the power to customize this powerful took back in the hands of non-flex-savvy developers. The look and feel is controlled by CSS, and any behavior is controlled by JavaScript. Flex only handles the file management portion. A nice result of this is that the flash file is only 46 kb, down from 288 kb. If you see any way that this can be done better, please don't hesitate to let me know!
|
8
|
+
|
9
|
+
h2. Example
|
10
|
+
|
11
|
+
!http://static.nathancolgate.com/images/s3_swf_uploader_screenshot.png!
|
12
|
+
|
13
|
+
Watch a video of an example app being built using the gem on "Vimeo":http://vimeo.com/11363680
|
14
|
+
|
15
|
+
There is also a demo app running on heroku at "http://s3swfuploader.heroku.com/":http://s3swfuploader.heroku.com/
|
16
|
+
|
17
|
+
h2. Usage
|
18
|
+
|
19
|
+
1. Edit <code>Gemfile</code> and add this as a gem
|
20
|
+
|
21
|
+
<pre><code>gem 's3_swf_upload', :git => 'git://github.com/nathancolgate/s3-swf-upload-plugin'
|
22
|
+
</code></pre>
|
23
|
+
|
24
|
+
2. Bundle it!
|
25
|
+
|
26
|
+
<pre><code>$ bundle install
|
27
|
+
</code></pre>
|
28
|
+
|
29
|
+
3. Run the generator
|
30
|
+
|
31
|
+
<pre><code>$ rails generate s3_swf_upload:uploader
|
32
|
+
</code></pre>
|
33
|
+
|
34
|
+
If you are using Rails 3.1, you will need to move the generated s3_upload.js from the public/javascripts directory to the app/assets/javascripts directory.
|
35
|
+
|
36
|
+
4. Configure your amazon parameters via the generated <code>config/amazon_s3.yml</code> file.
|
37
|
+
(key and secret can optionally be removed from that file and configured via <code>ENV['AWS_ACCESS_KEY_ID']</code> and <code>ENV['AWS_SECRET_ACCESS_KEY']</code>)
|
38
|
+
|
39
|
+
5. Make the bucket
|
40
|
+
|
41
|
+
There used to be a rake task for this, but it was removed so that there would be no dependency of aws/s3.
|
42
|
+
|
43
|
+
6. Upload the "crossdomain.xml file":https://github.com/nathancolgate/s3-swf-upload-plugin/blob/master/lib/s3_swf_upload/railties/tasks/crossdomain.xml
|
44
|
+
|
45
|
+
There used to be a rake task for this, but it was removed so that there would be no dependency of aws/s3.
|
46
|
+
|
47
|
+
Make sure the file is in the root and is publicly readable.
|
48
|
+
|
49
|
+
7. Note: you no longer need to edit <code>app/controller/s3_uploads_controller.rb</code>
|
50
|
+
|
51
|
+
In my tests in Rails 3, the application was able to correctly handle the requests from the flash object.
|
52
|
+
|
53
|
+
This means that your authentication systems can still be used to protect the signature generation.
|
54
|
+
|
55
|
+
8. Initialize the SWF object in your view using this handy helper:
|
56
|
+
|
57
|
+
<pre><code><%=raw s3_swf_upload_tag %>
|
58
|
+
</code></pre>
|
59
|
+
|
60
|
+
9. To achieve basic functionality, the only other thing you need is something to call the <code>startUploading</code> function. For example:
|
61
|
+
|
62
|
+
<pre><code><input type="submit" value="Start Uploading" onclick="s3_swf_1_object.startUploading();" />
|
63
|
+
</code></pre>
|
64
|
+
|
65
|
+
However, you will have no feedback or interface to let you know that anything is actually happening.
|
66
|
+
|
67
|
+
10. If you want to customise its behavior, "here's a more complex example":http://gist.github.com/382979
|
68
|
+
|
69
|
+
And the "CSS":http://gist.github.com/383118 to go along.
|
70
|
+
|
71
|
+
h2. File Renaming
|
72
|
+
|
73
|
+
In my applications I upload all files to _tmp_ folder and then have rails manipulate the file (renaming, resizing, etc). Here's a starting point to give you an idea of what that looks like using Paperclip:
|
74
|
+
|
75
|
+
"How to integrate with Paperclip":http://gist.github.com/575842
|
76
|
+
|
77
|
+
I prefer this solution because it allows the application to keep tabs on the files. However, if you are looking for a pure javascript solution, check out some of the forks of this project.
|
78
|
+
|
79
|
+
h2. General Parameters
|
80
|
+
|
81
|
+
h3. :buttonWidth _(integer = 100)_
|
82
|
+
|
83
|
+
h3. :buttonHeight _(integer = 30)_
|
84
|
+
|
85
|
+
h3. :flashVersion _(string = '9.0.0')_
|
86
|
+
|
87
|
+
h3. :queueSizeLimit _(integer = 100)_
|
88
|
+
|
89
|
+
Maximum number of files that can be added to the queue.
|
90
|
+
|
91
|
+
h3. :fileSizeLimit _(integer = 524288000)_
|
92
|
+
|
93
|
+
Individual file size limit in bytes (default is 512 MB)
|
94
|
+
|
95
|
+
h3. :fileTypes _(string = '*.*')_
|
96
|
+
|
97
|
+
Something like this also works: <code>'*.jpg;*.gif;*.png;'</code>
|
98
|
+
|
99
|
+
h3. :fileTypeDescs _(string = 'All Files')_
|
100
|
+
|
101
|
+
Something like this also works: <code>'Image files.'</code>
|
102
|
+
|
103
|
+
h3. :selectMultipleFiles _(boolean = true)_
|
104
|
+
|
105
|
+
Set this to false if you only want to allow users to pick one file at a time.
|
106
|
+
|
107
|
+
h3. :keyPrefix _(string = '')_
|
108
|
+
|
109
|
+
String to be prepended to the uploaded file name to make the Amazon S3 key (location in bucket).
|
110
|
+
|
111
|
+
h3. :signaturePath _(string = '/s3_uploads.xml')_
|
112
|
+
|
113
|
+
Fully qualified path to the controller and action that will serve up the Amazon S3 signature
|
114
|
+
|
115
|
+
h3. :swfFilePath _(string = '/flash/s3_upload.swf')_
|
116
|
+
|
117
|
+
Fully qualified path to the SWF file (this is the one that does all the work).
|
118
|
+
|
119
|
+
h3. :buttonUpPath _(string = '/flash/s3_up_button.gif')_
|
120
|
+
|
121
|
+
Fully qualified path to an image to be used as the Browse Button (in the up state). Image should have same dimensions as the buttonWidth and buttonHeight parameters.
|
122
|
+
|
123
|
+
h3. :buttonOverPath _(string = '/flash/s3_over_button.gif')_
|
124
|
+
|
125
|
+
Fully qualified path to an image to be used as the Browse Button (in the over state). Image should have same dimensions as the buttonWidth and buttonHeight parameters.
|
126
|
+
|
127
|
+
h3. :buttonDownPath _(string = '/flash/s3_down_button.gif')_
|
128
|
+
|
129
|
+
Fully qualified path to an image to be used as the Browse Button (in the down state). Image should have same dimensions as the buttonWidth and buttonHeight parameters.
|
130
|
+
|
131
|
+
h2. Callback Parameters
|
132
|
+
|
133
|
+
The real power of this refactoring is that the flex application makes all of the following calls to JavaScript. What you do with the calls is totally up to you:
|
134
|
+
|
135
|
+
* :onFileAdd _(file)_
|
136
|
+
* :onFileRemove _(file)_
|
137
|
+
* :onFileSizeLimitReached _(file)_
|
138
|
+
* :onFileNotInQueue _(file)_
|
139
|
+
* :onQueueChange _(queue)_
|
140
|
+
* :onQueueSizeLimitReached _(queue)_
|
141
|
+
* :onQueueEmpty _(queue)_
|
142
|
+
* :onQueueClear _(queue)_
|
143
|
+
* :onUploadingStart _()_
|
144
|
+
* :onUploadingStop _()_
|
145
|
+
* :onUploadingFinish _()_
|
146
|
+
* :onSignatureOpen _(file,event)_
|
147
|
+
* :onSignatureProgress _(file,progress_event)_
|
148
|
+
* :onSignatureSecurityError _(file,security_error_event)_
|
149
|
+
* :onSignatureComplete _(file,event)_
|
150
|
+
* :onSignatureIOError _(file,io_error_event)_
|
151
|
+
* :onSignatureHttpStatus _(file,http_status_event)_
|
152
|
+
* :onSignatureXMLError _(file,error_message)_
|
153
|
+
* :onUploadError _(upload_options,error)_
|
154
|
+
* :onUploadOpen _(upload_options,event)_
|
155
|
+
* :onUploadProgress _(upload_options,progress_event)_
|
156
|
+
* :onUploadIOError _(upload_options,io_error_event)_
|
157
|
+
* :onUploadHttpStatus _(upload_options,http_status_event)_
|
158
|
+
* :onUploadSecurityError _(upload_options,security_error_event)_
|
159
|
+
* :onUploadComplete _(upload_options,event)_
|
160
|
+
|
161
|
+
h2. JavaScript Functions
|
162
|
+
|
163
|
+
The following functions can be called on the generated object. Normally the call looks something like this:
|
164
|
+
|
165
|
+
<pre><code>s3_swf_1_object.startUploading();
|
166
|
+
</code></pre>
|
167
|
+
|
168
|
+
h3. startUploading
|
169
|
+
|
170
|
+
Starts the uploading process
|
171
|
+
|
172
|
+
h3. stopUploading
|
173
|
+
|
174
|
+
Stops the uploading process. Note: Stopping and restarting the uploading process is buggy. I'd avoid it.
|
175
|
+
|
176
|
+
h3. clearQueue
|
177
|
+
|
178
|
+
Clears all files out of the queue.
|
179
|
+
|
180
|
+
h3. removeFileFromQueue(integer)
|
181
|
+
|
182
|
+
Removes a specific file from the queue.
|
183
|
+
|
184
|
+
h2. Will it work with < Rails 3?
|
185
|
+
|
186
|
+
You bet. The Rails 3 specific gem only makes installation and setup easier. Here are some tips for getting this to work with < Rails 3:
|
187
|
+
|
188
|
+
* install it as a plugin <code>script/plugin install git://github.com/nathancolgate/s3-swf-upload-plugin.git</code>
|
189
|
+
* copy the "template files":http://github.com/nathancolgate/s3-swf-upload-plugin/tree/master/lib/s3_swf_upload/railties/generators/uploader/templates/ into your application (use the "generator":http://github.com/nathancolgate/s3-swf-upload-plugin/blob/master/lib/s3_swf_upload/railties/generators/uploader/uploader_generator.rb as a road map)
|
190
|
+
* copy the "view helpers":http://github.com/nathancolgate/s3-swf-upload-plugin/blob/master/lib/s3_swf_upload/view_helpers.rb into your applications <code>/lib</code> directory.
|
191
|
+
* add the view helper and integer monkey patch to an initialization file:
|
192
|
+
<code>
|
193
|
+
require 'view_helpers'
|
194
|
+
require 'patch/integer'
|
195
|
+
</code>
|
196
|
+
* load the config file by adding this to the bottom of your environment.rb file: <code>S3SwfUpload::S3Config.load_config</code>
|
197
|
+
* replace references to Rails.root or Rails.env in the <code>/vendor/plugins/s3-swf-upload-plugin/lib/s3_swf_upload/s3_config.rb</code> file.
|
198
|
+
* comment out the require railties inside <code>/vendor/plugins/s3-swf-upload-plugin/lib/s3_swf_upload.rb</code>
|
199
|
+
* you may need to require 's3_swf_upload' and 'aws/s3' in your environment.rb file
|
200
|
+
* your route will be map.resources instead of resources.
|
201
|
+
|
202
|
+
h2. Known Issues
|
203
|
+
|
204
|
+
1. As much as I would like the interface to be 100% HTML, a (legitimate) security feature in Flash does not allow it:
|
205
|
+
|
206
|
+
bq. "With Adobe Flash Player 10, the <code>FileReference.browse</code> and <code>FileReference.download</code> operations may be initiated only through ActionScript that originates from user interaction." - "Adobe TechNote":http://kb2.adobe.com/cps/405/kb405546.html
|
207
|
+
|
208
|
+
The next best thing I could come up with was to pass images in as buttons.
|
209
|
+
|
210
|
+
-If the <code>startUploading</code> call is made after calling <code>stopUploading</code>, only the first file in the queue is successfully uploaded.-
|
211
|
+
|
212
|
+
h2. Kudos
|
213
|
+
|
214
|
+
Original plugin is Copyright (c) 2008 elctech, released under the MIT license
|
215
|
+
|
216
|
+
Updates to plugin for multiple file uploader are Copyright (c) 2010 PRX, released under the MIT license
|
217
|
+
|
218
|
+
Conversion of plugin to gem for rails 3 is Copyright (c) 2010 Nathan Colgate Clark, released under the MIT license
|
219
|
+
|
220
|
+
Stripping the flex application of UI and adding callbacks Copyright (c) 2010 Nathan Colgate Clark, released under the MIT license
|
221
|
+
|
222
|
+
Thanks to yickster (Nick Merwin) for fixing the stopUploading issue
|
223
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new("s3_swf_upload") do |p|
|
6
|
+
p.author = "Nathan Colgate"
|
7
|
+
p.email = "nathan@brandnewbox.com"
|
8
|
+
p.description = "Rails 3 gem that allows you to upload files directly to S3 from your application using flex for file management, css for presentation, and javascript for behavior."
|
9
|
+
p.url = "http://github.com/nathancolgate/s3-swf-upload-plugin"
|
10
|
+
p.version = '0.3.2'
|
11
|
+
p.development_dependencies = []
|
12
|
+
p.ignore_pattern = [".gitignore"]
|
13
|
+
end
|
14
|
+
|