universal_s3_uploader 0.0.9 → 0.1.0
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.
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 73f63e41f9b6f24c596350c0bca808fe50e11c1b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 4b3f18c431c25c02d01920cdd2fc8bed9b2da69c
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 93e288b7fe0f14291dc9040ec6e6e98c7fd19b3cfe55fed8c8840a56d6c03e5a0d266f751d0a29da266542957bf56e845d48a663a459ca1ab2c12026c07b0eb3
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 518f68496c4e1e4c7e77fc1902641ed0bf76bd681280f8a3cbe6949c2137cc01999ac8b3aec58b0a09b6c7a616f577b6d3bb75cb8e358eb34c10e786477c9def
         
     | 
| 
         @@ -1,11 +1,9 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module UniversalS3Uploader
         
     | 
| 
       2 
2 
     | 
    
         
             
            	module ViewHelper
         
     | 
| 
       3 
     | 
    
         
            -
            		def universal_s3_uploader_tag(key, policy_name,  
     | 
| 
      
 3 
     | 
    
         
            +
            		def universal_s3_uploader_tag(key, policy_name, id)
         
     | 
| 
       4 
4 
     | 
    
         
             
            			uh = UploaderHelper.new(policy_name)
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
            			 
     | 
| 
       7 
     | 
    
         
            -
            				uh.tags(key).html_safe
         
     | 
| 
       8 
     | 
    
         
            -
            			end
         
     | 
| 
      
 6 
     | 
    
         
            +
            			uh.tags(key, id).html_safe
         
     | 
| 
       9 
7 
     | 
    
         
             
            		end
         
     | 
| 
       10 
8 
     | 
    
         | 
| 
       11 
9 
     | 
    
         
             
            		class UploaderHelper
         
     | 
| 
         @@ -20,7 +18,7 @@ module UniversalS3Uploader 
     | 
|
| 
       20 
18 
     | 
    
         
             
            				@policy = @config[policy_name]
         
     | 
| 
       21 
19 
     | 
    
         
             
            				@policy['conditions'] << ["starts-with", "$Filename", ""]	# for Flash upload
         
     | 
| 
       22 
20 
     | 
    
         
             
            				if @policy['expiration'] == '' || @policy['expiration'].nil?
         
     | 
| 
       23 
     | 
    
         
            -
            					@policy['expiration'] = 1.hour.from_now.iso8601
         
     | 
| 
      
 21 
     | 
    
         
            +
            					@policy['expiration'] = 1.hour.from_now.gmtime.iso8601
         
     | 
| 
       24 
22 
     | 
    
         
             
            				end
         
     | 
| 
       25 
23 
     | 
    
         
             
            			end
         
     | 
| 
       26 
24 
     | 
    
         | 
| 
         @@ -36,30 +34,36 @@ module UniversalS3Uploader 
     | 
|
| 
       36 
34 
     | 
    
         
             
            				raise 'No bucket name in policy Exception'
         
     | 
| 
       37 
35 
     | 
    
         
             
            			end
         
     | 
| 
       38 
36 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
            			def tags(key)
         
     | 
| 
      
 37 
     | 
    
         
            +
            			def tags(key, id)
         
     | 
| 
       40 
38 
     | 
    
         
             
            				av = ActionView::Base.new
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            				def div_tag(name, value)
         
     | 
| 
      
 41 
     | 
    
         
            +
            					"<div class=#{name} data-value=#{value}></div>"
         
     | 
| 
      
 42 
     | 
    
         
            +
            				end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
            				tag = "<div class='universal_s3_uploader' id='#{id}' action='#{url}'>"
         
     | 
| 
       42 
45 
     | 
    
         | 
| 
       43 
46 
     | 
    
         
             
            				([{key: key}] + @policy['conditions']).each do |condition|
         
     | 
| 
       44 
47 
     | 
    
         
             
            					if condition.class == Hash
         
     | 
| 
       45 
     | 
    
         
            -
            						tag +=  
     | 
| 
      
 48 
     | 
    
         
            +
            						tag += div_tag condition.keys.first, condition.values.first
         
     | 
| 
       46 
49 
     | 
    
         
             
            					elsif condition.class == Array
         
     | 
| 
       47 
50 
     | 
    
         
             
            						if condition[0] == 'eq' || condition[0] == 'starts-with'
         
     | 
| 
       48 
     | 
    
         
            -
            							tag +=  
     | 
| 
      
 51 
     | 
    
         
            +
            							tag += div_tag condition[1][1..-1], condition[2] unless condition[1] == '$key'
         
     | 
| 
       49 
52 
     | 
    
         
             
            						end
         
     | 
| 
       50 
53 
     | 
    
         
             
            					else
         
     | 
| 
       51 
54 
     | 
    
         
             
            						raise 'Something in policy unexpected'
         
     | 
| 
       52 
55 
     | 
    
         
             
            					end
         
     | 
| 
       53 
56 
     | 
    
         
             
            				end
         
     | 
| 
       54 
     | 
    
         
            -
            				tag +=  
     | 
| 
       55 
     | 
    
         
            -
            				tag +=  
     | 
| 
       56 
     | 
    
         
            -
            				tag +=  
     | 
| 
      
 57 
     | 
    
         
            +
            				tag += div_tag 'AWSAccessKeyId', @config['access_key_id']
         
     | 
| 
      
 58 
     | 
    
         
            +
            				tag += div_tag 'Policy', policy_encoded
         
     | 
| 
      
 59 
     | 
    
         
            +
            				tag += div_tag 'Signature', signature
         
     | 
| 
       57 
60 
     | 
    
         
             
            				tag += av.file_field_tag :file, multiple: true, accept: 'image/*'
         
     | 
| 
       58 
61 
     | 
    
         | 
| 
       59 
62 
     | 
    
         
             
            				tag += '<object id="flashUploader" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=11,1,0,0">'
         
     | 
| 
       60 
63 
     | 
    
         
             
            				tag += '<param name="movie" value="/assets/UniversalS3Uploader.swf">'
         
     | 
| 
       61 
64 
     | 
    
         
             
            				tag += '<param name="wmode" value="transparent">'
         
     | 
| 
       62 
65 
     | 
    
         
             
            				tag += '</object>'
         
     | 
| 
      
 66 
     | 
    
         
            +
            				tag += '</div>'
         
     | 
| 
       63 
67 
     | 
    
         
             
            			end
         
     | 
| 
       64 
68 
     | 
    
         | 
| 
       65 
69 
     | 
    
         
             
            			def bucket
         
     | 
| 
         Binary file 
     | 
| 
         @@ -49,8 +49,6 @@ 
     | 
|
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
                UniversalS3Uploader.prototype.init = function()
         
     | 
| 
       51 
51 
     | 
    
         
             
                {
         
     | 
| 
       52 
     | 
    
         
            -
                  this.element.children('div').remove();
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
52 
     | 
    
         
             
                  if (supportFormData)  // if supports HTML5 FormData
         
     | 
| 
       55 
53 
     | 
    
         
             
                  {
         
     | 
| 
       56 
54 
     | 
    
         
             
                    this.element.children('object#flashUploader').remove();
         
     | 
| 
         @@ -80,9 +78,10 @@ 
     | 
|
| 
       80 
78 
     | 
    
         
             
                  {
         
     | 
| 
       81 
79 
     | 
    
         
             
                    var flashObject = this.element.children('object').get(0);
         
     | 
| 
       82 
80 
     | 
    
         | 
| 
       83 
     | 
    
         
            -
                    this.element. 
     | 
| 
      
 81 
     | 
    
         
            +
                    flashObject.sendDivId(this.element.attr('id'));
         
     | 
| 
      
 82 
     | 
    
         
            +
                    this.element.children('div').each(function ()
         
     | 
| 
       84 
83 
     | 
    
         
             
                    {
         
     | 
| 
       85 
     | 
    
         
            -
                      flashObject.sendFormData(this. 
     | 
| 
      
 84 
     | 
    
         
            +
                      flashObject.sendFormData(this.className, $(this).data('value'));
         
     | 
| 
       86 
85 
     | 
    
         
             
                    });
         
     | 
| 
       87 
86 
     | 
    
         
             
                  }
         
     | 
| 
       88 
87 
     | 
    
         
             
                };
         
     | 
| 
         @@ -101,9 +100,9 @@ 
     | 
|
| 
       101 
100 
     | 
    
         
             
                UniversalS3Uploader.prototype.upload = function(file, index)
         
     | 
| 
       102 
101 
     | 
    
         
             
                {
         
     | 
| 
       103 
102 
     | 
    
         
             
                  var fd = new FormData();
         
     | 
| 
       104 
     | 
    
         
            -
                  this.element.children(' 
     | 
| 
      
 103 
     | 
    
         
            +
                  this.element.children('div').each(function()
         
     | 
| 
       105 
104 
     | 
    
         
             
                  {
         
     | 
| 
       106 
     | 
    
         
            -
                    fd.append(this. 
     | 
| 
      
 105 
     | 
    
         
            +
                    fd.append(this.className, $(this).data('value'));
         
     | 
| 
       107 
106 
     | 
    
         
             
                  });
         
     | 
| 
       108 
107 
     | 
    
         
             
                  fd.append('file', file);
         
     | 
| 
       109 
108 
     | 
    
         |