gemini_upload-rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -26,6 +26,9 @@ $.fn.extend({
|
|
26
26
|
encode: function(key, secret) {
|
27
27
|
return btoa(unescape(encodeURIComponent([key, secret].join(':'))));
|
28
28
|
},
|
29
|
+
uid: function() {
|
30
|
+
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
|
31
|
+
},
|
29
32
|
seedForm: function(data, options) {
|
30
33
|
var $form, acl, base64Policy, bucket, key, s3Key, signature, successAction, uploadBucket;
|
31
34
|
bucket = data.policy_document.conditions[0].bucket;
|
@@ -43,26 +46,29 @@ $.fn.extend({
|
|
43
46
|
$form.find('input[name=success_action_status]').val(successAction);
|
44
47
|
$form.find('input[name=policy]').val(base64Policy);
|
45
48
|
$form.find('input[name=signature]').val(signature);
|
49
|
+
if (typeof options.multiple != 'undefined' && options.multiple) {
|
50
|
+
$form.find('input[name=file]').attr('multiple', true);
|
51
|
+
}
|
46
52
|
return $form.get(0).setAttribute('action', "https://" + uploadBucket + ".s3.amazonaws.com");
|
47
53
|
},
|
48
54
|
attachFileUploadUI: function(data, options) {
|
49
|
-
var $form, bucket, key, metadata;
|
55
|
+
var $form, bucket, key, metadata, originalKey;
|
50
56
|
$form = this.find('form');
|
51
57
|
bucket = data.policy_document.conditions[0].bucket;
|
52
|
-
|
58
|
+
originalKey = "" + data.policy_document.conditions[1][2] + "/${filename}";
|
53
59
|
this.seedForm(data, options);
|
54
|
-
metadata =
|
55
|
-
_type: options._type,
|
56
|
-
id: options.id
|
57
|
-
};
|
60
|
+
metadata = options.metadata;
|
58
61
|
return $form.fileupload({
|
59
62
|
type: 'POST',
|
60
63
|
dataType: 'xml',
|
61
64
|
done: (function(_this) {
|
62
65
|
return function(e, data) {
|
63
66
|
var fileName;
|
67
|
+
if (typeof options.onDone != 'undefined' && options.onDone != null) {
|
68
|
+
options.onDone(e, data);
|
69
|
+
}
|
64
70
|
fileName = data.files[0].name;
|
65
|
-
key =
|
71
|
+
key = originalKey.replace('${filename}', fileName);
|
66
72
|
return $.ajax({
|
67
73
|
type: 'POST',
|
68
74
|
dataType: 'json',
|
@@ -79,8 +85,8 @@ $.fn.extend({
|
|
79
85
|
'Authorization': "Basic " + options.credentials
|
80
86
|
},
|
81
87
|
success: function(resp) {
|
82
|
-
if (options.successCb
|
83
|
-
|
88
|
+
if (typeof options.successCb != 'undefined' && options.successCb != null) {
|
89
|
+
options.successCb(resp);
|
84
90
|
}
|
85
91
|
}
|
86
92
|
});
|
@@ -88,13 +94,18 @@ $.fn.extend({
|
|
88
94
|
})(this),
|
89
95
|
add: (function(_this) {
|
90
96
|
return function(e, data) {
|
97
|
+
if (typeof options.onIndividualFile != 'undefined' && options.onIndividualFile != null) {
|
98
|
+
options.onIndividualFile(e, _.extend(data, { uid: _this.uid() }));
|
99
|
+
}
|
91
100
|
var fileName, fileType;
|
92
101
|
fileName = data.files[0].name;
|
93
102
|
fileType = data.files[0].type;
|
94
103
|
$(_this).find("form input[name='Content-Type']").val(fileType);
|
95
104
|
return data.submit();
|
96
105
|
};
|
97
|
-
})(this)
|
106
|
+
})(this),
|
107
|
+
fail: options.onFail,
|
108
|
+
progress: options.onProgress
|
98
109
|
});
|
99
110
|
}
|
100
111
|
});
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemini_upload-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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: 2014-07
|
12
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -68,7 +68,7 @@ extra_rdoc_files: []
|
|
68
68
|
files:
|
69
69
|
- lib/gemini_upload/rails/version.rb
|
70
70
|
- lib/gemini_upload/rails.rb
|
71
|
-
- vendor/assets/
|
71
|
+
- vendor/assets/javascripts/gemini/gemini_upload.js
|
72
72
|
- LICENSE.txt
|
73
73
|
- README.md
|
74
74
|
homepage: ''
|