s3_cors_fileupload 0.2.0.pre1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79391b654debb51c6dd03fe45b28cb12a1d06065
4
- data.tar.gz: b06c05d0b17b59e005c8569e256356573fc88472
3
+ metadata.gz: c2cfe9cc0074544ce499718dcade6db5f33a0f51
4
+ data.tar.gz: da9078e43ca4632005d14abd7722fa5ec91e28cc
5
5
  SHA512:
6
- metadata.gz: c5637708ed1fb4f9c7d387f854e46817c70d3d29207f5faa14dfa7d8add69756c60d7a22f9024d955a7f373aa948725aa35d04faf1cd2615d91960b446c0d59a
7
- data.tar.gz: ddf94cb6e3e397f1d4f8b20b5af3b441697c523b506290a1215188f86677d6f1ac24d191f9bd4d824f4a4e3847407113481d41eddc30a54226b06c276fbf42d4
6
+ metadata.gz: c34ea6dcfdcbd365338edae0d6c9360bb99a4b4fb8023c3f2650775af59455cef3fc14e965677e9dff9f041faed8ce3fcf1f636a70b5fb32974610f8b6e1cd9c
7
+ data.tar.gz: 80b107368d59fb206ea925c414047750d829208b425a318846b4e37a5deac53987517f3672f97d9f86f0f0e637aabe82caf09b43a23ad7f36caccdc02d9c5d66
@@ -3,6 +3,7 @@
3
3
  - Upgraded jQuery-File-Upload and the other JavaScript files it is dependent upon to the most recent releases (see [lib/s3\_cors\_fileupload/version.rb](https://github.com/fullbridge-batkins/s3_cors_fileupload/blob/master/lib/s3_cors_fileupload/version.rb) for the current version #'s)
4
4
  - Adjusted the `s3_cors_fileupload_form_tag` view helper so that block arguments passed to it are inserted inside of the form tag as opposed to the end of it.
5
5
  - Changed the default expiration time for the form from 1 hour to 10 hours.
6
+ - Swapped in [MultiJSON](https://github.com/intridea/multi_json) for the JSON gem.
6
7
  - Added a lot more spec coverage.
7
8
 
8
9
  ## 0.1.5
@@ -39,16 +39,16 @@ $(function() {
39
39
  });
40
40
 
41
41
  $('#fileupload').bind('fileuploaddone', function (e, data) {
42
- // the response will be XML, and can be accessed by calling `data.result`
43
- //
44
- // Here is an example of what the XML will look like coming back from S3:
45
- // <PostResponse>
46
- // <Location>https://bucket-name.s3.amazonaws.com/uploads%2F3ducks.jpg</Location>
47
- // <Bucket>bucket-name</Bucket>
48
- // <Key>uploads/3ducks.jpg</Key>
49
- // <ETag>"c7902ef289687931f34f92b65afda320"</ETag>
50
- // </PostResponse>
51
-
42
+ // the response will be XML, and can be accessed by calling `data.result`
43
+ //
44
+ // Here is an example of what the XML will look like coming back from S3:
45
+ // <PostResponse>
46
+ // <Location>https://bucket-name.s3.amazonaws.com/uploads%2F3ducks.jpg</Location>
47
+ // <Bucket>bucket-name</Bucket>
48
+ // <Key>uploads/3ducks.jpg</Key>
49
+ // <ETag>"c7902ef289687931f34f92b65afda320"</ETag>
50
+ // </PostResponse>
51
+
52
52
  $.post('/source_files.json',
53
53
  {
54
54
  'source_file[url]': $(data.result).find('Location').text(),
@@ -63,10 +63,17 @@ $(function() {
63
63
  );
64
64
  });
65
65
 
66
- // remove the table row containing the source file information from the page
66
+ $('#fileupload').bind('fileuploadcompleted', function (e, data) {
67
+ // remove the downloaded templates, since in the above function we put our own custom 'template-uploaded' onto the list instead
68
+ data.context.remove();
69
+ });
70
+
67
71
  $('#fileupload').bind('fileuploaddestroyed', function (e, data) {
68
- var deleted_object_id = data.url.split('/').pop();
69
- // now remove the element from the page
72
+ if (!data.url) // sometimes this callback seems to get triggered a couple times, and has null data after the first time
73
+ return null;
74
+
75
+ var deleted_object_id = String(data.url).split('/').pop();
76
+ // remove the table row containing the source file information from the page
70
77
  $('#source_file_' + deleted_object_id).remove();
71
78
  });
72
79
 
@@ -75,14 +82,12 @@ $(function() {
75
82
  // used for displaying approximate file size on the file listing index.
76
83
  // functionality mimics what the jQuery-File-Upload script does.
77
84
  function formatFileSize(bytes) {
78
- if (typeof bytes !== 'number') {
79
- return '';
80
- }
81
- if (bytes >= 1000000000) {
82
- return (bytes / 1000000000).toFixed(2) + ' GB';
83
- }
84
- if (bytes >= 1000000) {
85
- return (bytes / 1000000).toFixed(2) + ' MB';
86
- }
87
- return (bytes / 1000).toFixed(2) + ' KB';
85
+ if (typeof bytes !== 'number')
86
+ return '';
87
+ else if (bytes >= 1000000000)
88
+ return (bytes / 1000000000).toFixed(2) + ' GB';
89
+ else if (bytes >= 1000000)
90
+ return (bytes / 1000000).toFixed(2) + ' MB';
91
+ else
92
+ return (bytes / 1000).toFixed(2) + ' KB';
88
93
  }
@@ -6,8 +6,8 @@
6
6
 
7
7
  <div class="javascript-templates">
8
8
  <%= render 'template_upload' %>
9
+ <%= render 'template_download' %>
9
10
  <%= render 'template_uploaded' %>
10
- <%# render 'template_download' %>
11
11
  </div>
12
12
  </div>
13
13
 
@@ -17,9 +17,7 @@
17
17
  // Initialize the jQuery File Upload widget:
18
18
  $('#fileupload').fileupload({
19
19
  dataType: 'xml',
20
- sequentialUploads: true,
21
- downloadTemplateId: null,
22
- downloadTemplate: null
20
+ sequentialUploads: true
23
21
  });
24
22
 
25
23
  // Load existing files:
@@ -10,8 +10,8 @@
10
10
  %td.size
11
11
  %span {%=o.formatFileSize(file.size)%}
12
12
  %td.error{:colspan => "2"}
13
- %span.label.label-important {%=locale.fileupload.error%}
14
- {%=locale.fileupload.errors[file.error] || file.error%}
13
+ %span.label.label-important Error
14
+ {%=file.error%}
15
15
  {% } else { %}
16
16
  %td.preview
17
17
  {% if (file.thumbnail_url) { %}
@@ -19,7 +19,7 @@
19
19
  %img{:src => "{%=file.thumbnail_url%}"}/
20
20
  {% } %}
21
21
  %td.name
22
- %a{:download => "{%=file.name%}", :href => "{%=file.url%}", :rel => "{%=file.thumbnail_url&&'gallery'%}", :title => "{%=file.name%}"} {%=file.name%}
22
+ %a{:download => "{%=file.name%}", :href => "{%=file.url%}", :rel => "{%=file.thumbnail_url&&'gallery'%}".html_safe, :title => "{%=file.name%}"} {%=file.name%}
23
23
  %td.size
24
24
  %span {%=$('#fileupload').formatFileSize(file.size)%}
25
25
  %td{:colspan => "2"}
@@ -6,17 +6,15 @@
6
6
 
7
7
  .javascript-templates
8
8
  = render 'template_upload'
9
+ = render 'template_download'
9
10
  = render 'template_uploaded'
10
- =# render 'template_download'
11
11
 
12
12
  :javascript
13
13
  $(function () {
14
14
  // Initialize the jQuery File Upload widget:
15
15
  $('#fileupload').fileupload({
16
16
  dataType: 'xml',
17
- sequentialUploads: true,
18
- downloadTemplateId: null,
19
- downloadTemplate: null
17
+ sequentialUploads: true
20
18
  });
21
19
 
22
20
  // Load existing files:
@@ -21,7 +21,7 @@ module S3CorsFileupload
21
21
  hidden_form_fields = {
22
22
  :key => '',
23
23
  'Content-Type' => '',
24
- 'AWSAccessKeyId' => options[:access_key_id] || Config.access_key_id,
24
+ :AWSAccessKeyId => options[:access_key_id] || Config.access_key_id,
25
25
  :acl => policy_helper.options[:acl],
26
26
  :policy => policy_helper.policy_document,
27
27
  :signature => policy_helper.upload_signature,
@@ -1,7 +1,7 @@
1
1
  require 'base64'
2
2
  require 'openssl'
3
3
  require 'digest/sha1'
4
- require 'json'
4
+ require 'multi_json'
5
5
 
6
6
  module S3CorsFileupload
7
7
  class PolicyHelper
@@ -18,31 +18,35 @@ module S3CorsFileupload
18
18
 
19
19
  # generate the policy document that amazon is expecting.
20
20
  def policy_document
21
- Base64.encode64(
22
- {
23
- expiration: 10.hours.from_now.utc.iso8601(3),
24
- conditions: [
25
- { bucket: options[:bucket] },
26
- { acl: options[:acl] },
27
- { success_action_status: '201' },
28
- ["content-length-range", 0, options[:max_file_size]],
29
- ["starts-with", "$utf8", ""],
30
- ["starts-with", "$key", ""],
31
- ["starts-with", "$Content-Type", ""]
32
- ]
33
- }.to_json
34
- ).gsub(/\n|\r/, '')
21
+ @policy_document ||=
22
+ Base64.encode64(
23
+ MultiJson.dump(
24
+ {
25
+ expiration: 10.hours.from_now.utc.iso8601(3),
26
+ conditions: [
27
+ { bucket: options[:bucket] },
28
+ { acl: options[:acl] },
29
+ { success_action_status: '201' },
30
+ ["content-length-range", 0, options[:max_file_size]],
31
+ ["starts-with", "$utf8", ""],
32
+ ["starts-with", "$key", ""],
33
+ ["starts-with", "$Content-Type", ""]
34
+ ]
35
+ }
36
+ )
37
+ ).gsub(/\n/, '')
35
38
  end
36
39
 
37
40
  # sign our request by Base64 encoding the policy document.
38
41
  def upload_signature
39
- Base64.encode64(
40
- OpenSSL::HMAC.digest(
41
- OpenSSL::Digest::SHA1.new,
42
- options[:secret_access_key],
43
- self.policy_document
44
- )
45
- ).gsub(/\n/, '')
42
+ @upload_signature ||=
43
+ Base64.encode64(
44
+ OpenSSL::HMAC.digest(
45
+ OpenSSL::Digest::SHA1.new,
46
+ options[:secret_access_key],
47
+ self.policy_document
48
+ )
49
+ ).gsub(/\n/, '')
46
50
  end
47
51
  end
48
52
  end
@@ -1,5 +1,5 @@
1
1
  module S3CorsFileupload
2
- VERSION = '0.2.0.pre1'
2
+ VERSION = '0.2.0'
3
3
  JQUERY_FILEUPLOAD_VERSION = '5.26'
4
4
  JQUERY_FILEUPLOAD_UI_VERSION = '7.4.1'
5
5
  end
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.rdoc_options = %w(--charset=UTF-8)
25
25
 
26
26
  s.add_dependency('rails', ['~> 3.1'])
27
+ s.add_dependency('multi_json', ['~> 1.0'])
27
28
  s.add_dependency('jquery-rails', ['>= 2.0'])
28
29
  s.add_dependency('aws-s3', ['~> 0.6']) # :require => 'aws/s3'
29
30
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_cors_fileupload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.pre1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Atkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-30 00:00:00.000000000 Z
11
+ date: 2013-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: jquery-rails
29
43
  requirement: !ruby/object:Gem::Requirement