s3_direct_upload 0.0.2 → 0.0.3
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/README.md +1 -1
- data/app/assets/javascripts/s3_direct_upload.js.coffee +91 -91
- data/lib/s3_direct_upload/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -1,94 +1,94 @@
|
|
1
1
|
#= require jquery-fileupload/basic
|
2
2
|
#= require jquery-fileupload/vendor/tmpl
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
)
|
4
|
+
$ = jQuery
|
5
|
+
|
6
|
+
$.fn.S3Uploader = (options) ->
|
7
|
+
|
8
|
+
# support multiple elements
|
9
|
+
if @length > 1
|
10
|
+
@each ->
|
11
|
+
$(this).S3Uploader options
|
12
|
+
|
13
|
+
return this
|
14
|
+
|
15
|
+
$uploadForm = this
|
16
|
+
|
17
|
+
settings =
|
18
|
+
path: ''
|
19
|
+
additional_data: null
|
20
|
+
before_add: null
|
21
|
+
|
22
|
+
$.extend settings, options
|
23
|
+
|
24
|
+
current_files = []
|
25
|
+
|
26
|
+
setUploadForm = ->
|
27
|
+
$uploadForm.fileupload
|
28
|
+
|
29
|
+
add: (e, data) ->
|
30
|
+
current_files.push data
|
31
|
+
file = data.files[0]
|
32
|
+
unless settings.before_add and not settings.before_add(file)
|
33
|
+
data.context = $(tmpl("template-upload", file))
|
34
|
+
$uploadForm.append(data.context)
|
35
|
+
data.submit()
|
36
|
+
|
37
|
+
progress: (e, data) ->
|
38
|
+
if data.context
|
39
|
+
progress = parseInt(data.loaded / data.total * 100, 10)
|
40
|
+
data.context.find('.bar').css('width', progress + '%')
|
41
|
+
|
42
|
+
done: (e, data) ->
|
43
|
+
file = data.files[0]
|
44
|
+
domain = $uploadForm.attr('action')
|
45
|
+
path = settings.path + $uploadForm.find('input[name=key]').val().replace('/${filename}', '')
|
46
|
+
to = $uploadForm.data('post')
|
47
|
+
content = {}
|
48
|
+
content[$uploadForm.data('as')] = domain + path + '/' + file.name
|
49
|
+
content.filename = file.name
|
50
|
+
content.filepath = path
|
51
|
+
if settings.additional_data
|
52
|
+
content = $.extend content, settings.additional_data
|
53
|
+
if 'size' of file
|
54
|
+
content.filesize = file.size
|
55
|
+
if 'type' of file
|
56
|
+
content.filetype = file.type
|
57
|
+
|
58
|
+
$.post(to, content)
|
59
|
+
data.context.remove() if data.context # remove progress bar
|
60
|
+
|
61
|
+
current_files.splice($.inArray(data, current_files), 1) # remove that element from the array
|
62
|
+
if current_files.length == 0
|
63
|
+
$(document).trigger("s3_uploads_complete")
|
64
|
+
|
65
|
+
fail: (e, data) ->
|
66
|
+
alert("#{data.files[0].name} failed to upload.")
|
67
|
+
console.log("Upload failed:")
|
68
|
+
console.log(data)
|
69
|
+
|
70
|
+
formData: (form) ->
|
71
|
+
data = form.serializeArray()
|
72
|
+
fileType = ""
|
73
|
+
if "type" of @files[0]
|
74
|
+
fileType = @files[0].type
|
75
|
+
data.push
|
76
|
+
name: "Content-Type"
|
77
|
+
value: fileType
|
78
|
+
|
79
|
+
data[1].value = settings.path + data[1].value
|
80
|
+
|
81
|
+
data
|
82
|
+
|
83
|
+
#public methods
|
84
|
+
@initialize = ->
|
85
|
+
setUploadForm()
|
86
|
+
this
|
87
|
+
|
88
|
+
@path = (new_path) ->
|
89
|
+
settings.path = new_path
|
90
|
+
|
91
|
+
@additional_data = (new_data) ->
|
92
|
+
settings.additional_data = new_data
|
93
|
+
|
94
|
+
@initialize()
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- Wayne Hoover
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
version: 0.3.4
|
78
78
|
description: Direct Upload to Amazon S3 With CORS and jquery-file-upload
|
79
79
|
email:
|
80
|
-
-
|
80
|
+
- w@waynehoover.com
|
81
81
|
executables: []
|
82
82
|
extensions: []
|
83
83
|
extra_rdoc_files: []
|