Module: AppliciousUtils::ViewHelpers
- Defined in:
- lib/applicious_utils/view_helpers.rb
Instance Method Summary collapse
-
#applicious_uploader(options) ⇒ Object
Derived from github.com/iwasrobbed/Rails3-S3-Uploader-Plupload.
Instance Method Details
#applicious_uploader(options) ⇒ Object
Derived from github.com/iwasrobbed/Rails3-S3-Uploader-Plupload
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 95 96 |
# File 'lib/applicious_utils/view_helpers.rb', line 7 def applicious_uploader() [:s3_config_filename] ||= Rails.root.join('config', 'amazon_s3.yml') config = YAML.load_file([:s3_config_filename])[Rails.env].symbolize_keys bucket = config[:bucket_name] access_key_id = config[:access_key_id] secret_access_key = config[:secret_access_key] [:key] ||= 'uploads' # folder on AWS to store file in [:acl] ||= 'public-read' [:expiration_date] ||= 10.hours.from_now.utc.iso8601 [:max_filesize] ||= 500.megabytes #options[:button_id] filename_token = SecureRandom.uuid + '_' + Time.now.to_i.to_s id = [:id] ? "_#{[:id]}" : '' policy = Base64.encode64( "{'expiration': '#{[:expiration_date]}', 'conditions': [ {'bucket': '#{bucket}'}, {'acl': '#{[:acl]}'}, {'success_action_status': '201'}, ['content-length-range', 0, #{[:max_filesize]}], ['starts-with', '$key', ''], ['starts-with', '$Content-Type', ''], ['starts-with', '$name', ''], ['starts-with', '$Filename', ''] ] }").gsub(/\n|\r/, '') signature = Base64.encode64( OpenSSL::HMAC.digest( OpenSSL::Digest::Digest.new('sha1'), secret_access_key, policy)).gsub("\n","") out = "" out << javascript_tag("$(function() { /* * S3 Uploader instance */ var applicious_uploader = new plupload.Uploader({ preinit : { UploadFile: function(up, file) { up.settings.multipart_params: { 'key': 'uploads/#{filename_token}.' + file.name.split('.').pop(), 'Filename': 'uploads/#{filename_token}.' + file.name.split('.').pop(), 'acl': '#{[:acl]}', 'Content-Type': '#{[:content_type]}', 'success_action_status': '201', 'AWSAccessKeyId' : '#{access_key_id}', 'policy': '#{policy}', 'signature': '#{signature}' } } }, runtimes : 'flash,silverlight', browse_button : '#{[:button_id]}', max_file_size : '500mb', url : 'http://#{bucket}.s3.amazonaws.com/', flash_swf_url: '/applicious/plupload/plupload.flash.swf', silverlight_xap_url: '/applicious/plupload/plupload.silverlight.xap', multi_selection: false, //resize : {width : 320, height : 240, quality : 90}, multipart: true, /* multipart_params: { 'acl': '#{[:acl]}', 'Content-Type': '#{[:content_type]}', 'success_action_status': '201', 'AWSAccessKeyId' : '#{access_key_id}', 'policy': '#{policy}', 'signature': '#{signature}' }, */ filters : [ {title : '#{[:filter_title]}', extensions : '#{[:filter_extensions]}'} ], file_data_name: 'file' }); AP.Uploader.init( applicious_uploader, '#{filename_token}' ) });") end |