azure_direct_upload 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 364e1ea86f11acc7e63b9b0a4cca26bf53e55ec7
4
+ data.tar.gz: 9978c35cb4ce461cd4cb3f3df18c8b1d67bcbaed
5
+ SHA512:
6
+ metadata.gz: 826b9ddc55720469d59510747791f1621e41dc60aaa0a490baccd1341e74c9737e9d2275f9991a837aa9063a885cecebcf2f0c5131deeb1ff3c1be4ad24f2209
7
+ data.tar.gz: a4d946e5c08e8c65e2bc31307dc68fbb2b5dbde6a116abcd0abf591bcf4d3d54843a86da632c8f946ba3dd6e088078e4bf542af38e1383e0cde3035f5123c821
@@ -0,0 +1,20 @@
1
+ Copyright 2015 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'AzureDirectUpload'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
@@ -0,0 +1,122 @@
1
+ #= require jquery-fileupload/basic
2
+ #= require jquery-fileupload/vendor/tmpl
3
+
4
+ $ = jQuery
5
+
6
+ $.fn.azure_direct_upload = (options) ->
7
+
8
+ pad = (n, width, z) ->
9
+ z = z or '0'
10
+ n = n + ''
11
+ if n.length >= width then n else new Array(width - n.length + 1).join(z) + n
12
+
13
+ if @length > 1
14
+ @each ->
15
+ $(this).azure_direct_upload options
16
+
17
+ return this
18
+
19
+ form = this
20
+
21
+ settings =
22
+ path: ''
23
+ drop_zone: null,
24
+ callbacks:
25
+ add: null
26
+ progress: null
27
+ done: null
28
+ fail: null
29
+ submit: null
30
+ chunksend: null
31
+ chunkdone: null
32
+
33
+ $.extend settings, options
34
+
35
+ setup = ->
36
+ form.fileupload
37
+ type: "PUT",
38
+ headers:
39
+ "x-ms-page-write": "update"
40
+ "x-ms-version": "2013-08-15"
41
+ multipart: false,
42
+ maxChunkSize: 4000000,
43
+ maxFileSize: form.data("max-file-size"),
44
+ dropZone: settings.drop_zone,
45
+ add: (e, data) ->
46
+ file = data.files[0]
47
+ file.commit_data = {}
48
+
49
+ $.ajax
50
+ type: "POST",
51
+ url: form.data("sas-url"),
52
+ data:
53
+ file_name: file.name,
54
+ container: form.data("container"),
55
+ size: file.size,
56
+ settings:
57
+ sas_permissions: form.data("sas-permissions"),
58
+ sas_expiration: form.data("sas-expiration"),
59
+
60
+ beforeSend: ( xhr, settings ) -> form.trigger( 'ajax:beforeSend', [xhr, settings] )
61
+ complete: ( xhr, status ) -> form.trigger( 'ajax:complete', [xhr, status] )
62
+ success: ( response_data, status, xhr ) ->
63
+ data.files[0].blockno = 0
64
+ data.files[0].chunksent = false
65
+ data.files[0].base_url = response_data.uri
66
+ data.url = data.files[0].base_url.replace("BLOCK_ID", btoa(pad(data.files[0].blockno, 5)))
67
+ form.trigger( 'ajax:success', [data, status, xhr] )
68
+
69
+ settings.callbacks.add(data, response_data) if settings.callbacks.add
70
+
71
+ data.submit()
72
+
73
+ error: ( xhr, status, error ) -> form.trigger( 'ajax:error', [xhr, status, error] )
74
+
75
+ progress: (e, data) ->
76
+ settings.callbacks.progress(data) if settings.callbacks.progress
77
+
78
+ done: (e, data) ->
79
+ file = data.files[0]
80
+
81
+ $.ajax
82
+ type: "POST",
83
+ url: form.data("commit-url"),
84
+ data:
85
+ blockno: file.blockno,
86
+ file_name: file.name,
87
+ container: form.data("container"),
88
+ size: file.size,
89
+ commit_data: file.commit_data
90
+
91
+ beforeSend: ( xhr, settings ) -> form.trigger( 'ajax:beforeSend', [xhr, settings] )
92
+ complete: ( xhr, status ) -> form.trigger( 'ajax:complete', [xhr, status] )
93
+ success: ( response_data, status, xhr ) ->
94
+ form.trigger( 'ajax:success', [data, status, xhr] )
95
+
96
+ settings.callbacks.done(data, response_data) if settings.callbacks.done
97
+ error: ( xhr, status, error ) -> form.trigger( 'ajax:error', [xhr, status, error] )
98
+
99
+ fail: (e, data) ->
100
+ settings.callbacks.fail(data) if settings.callbacks.fail
101
+
102
+ #formData: (form) ->
103
+
104
+ submit: (e, data) ->
105
+ settings.callbacks.submit(data) if settings.callbacks.submit
106
+
107
+ chunksend: (e, data) =>
108
+ if data.files[0].chunksent
109
+ data.files[0].blockno++
110
+ data.url = data.files[0].base_url.replace("BLOCK_ID", btoa(pad(data.files[0].blockno, 5)))
111
+
112
+ data.files[0].chunksent = true
113
+ settings.callbacks.chunksend(data) if settings.callbacks.chunksend
114
+ chunkdone: (e, data) =>
115
+ settings.callbacks.chunkdone(data) if settings.callbacks.chunkdone
116
+
117
+ #public methods
118
+ @initialize = ->
119
+ setup()
120
+ this
121
+
122
+ @initialize()
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ module AzureDirectUpload
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+ module AzureDirectUpload
2
+ class SasController < ApplicationController
3
+ def sign
4
+ bs = Azure::Blob::BlobService.new
5
+ @uri = bs.generate_uri Addressable::URI.escape("#{container_name}/#{blob_name}"), {comp: "block", blockid: "BLOCK_ID"}
6
+
7
+ signer = Azure::Contrib::Auth::SharedAccessSignature.new(@uri, {
8
+ resource: "b",
9
+ permissions: permissions,
10
+ start: start_time.utc.iso8601,
11
+ expiry: expiration_time.utc.iso8601
12
+ }, Azure.config.storage_account_name)
13
+
14
+ @uri = signer.sign
15
+
16
+ render response_hash
17
+ end
18
+
19
+ private
20
+
21
+ def container_name
22
+ params[:container]
23
+ end
24
+
25
+ def blob_name
26
+ params[:file_name]
27
+ end
28
+
29
+ def permissions
30
+ params[:settings][:sas_permissions]
31
+ end
32
+
33
+ def start_time
34
+ Time.now - 10.seconds
35
+ end
36
+
37
+ def expiration_time
38
+ Time.now + params[:settings][:sas_expiration].to_i
39
+ end
40
+
41
+ def response_hash
42
+ {text: @uri}
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,29 @@
1
+ module AzureDirectUpload
2
+ class UploadController < ApplicationController
3
+ def commit
4
+ bs = Azure::Blob::BlobService.new
5
+ block_list = (0..blockno).collect{|i| [sprintf("%05d", i)]}
6
+ bs.commit_blob_blocks(container_name, blob_name, block_list)
7
+
8
+ render response_hash
9
+ end
10
+
11
+ private
12
+
13
+ def container_name
14
+ params[:container]
15
+ end
16
+
17
+ def blob_name
18
+ params[:file_name]
19
+ end
20
+
21
+ def blockno
22
+ params[:blockno].to_i
23
+ end
24
+
25
+ def response_hash
26
+ {text: "commited"}
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ module AzureDirectUpload
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>AzureDirectUpload</title>
5
+ <%= stylesheet_link_tag "azure_direct_upload/application", media: "all" %>
6
+ <%= javascript_include_tag "azure_direct_upload/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ AzureDirectUpload::Engine.routes.draw do
2
+ post "sign", to: "sas#sign", as: :sas_sign
3
+ post "commit", to: "upload#commit", as: :upload_commit
4
+ end
@@ -0,0 +1,12 @@
1
+ require "azure_direct_upload/engine"
2
+ require "azure_direct_upload/railtie"
3
+
4
+ require "azure_direct_upload/config"
5
+ require "azure_direct_upload/form_helper"
6
+
7
+ module AzureDirectUpload
8
+ end
9
+
10
+ ActiveSupport.on_load(:action_view) do
11
+ include AzureDirectUpload::UploadHelper
12
+ end
@@ -0,0 +1,18 @@
1
+ require "singleton"
2
+
3
+ module AzureDirectUpload
4
+ class Config
5
+ include Singleton
6
+
7
+ ATTRIBUTES = []
8
+
9
+ attr_accessor *ATTRIBUTES
10
+ end
11
+
12
+ def self.config
13
+ if block_given?
14
+ yield Config.instance
15
+ end
16
+ Config.instance
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module AzureDirectUpload
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace AzureDirectUpload
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec
7
+ end
8
+
9
+ config.to_prepare do
10
+ Dir.glob(Rails.root + "app/decorators/**/*_decorator*.rb").each do |c|
11
+ require_dependency(c)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,54 @@
1
+ module AzureDirectUpload
2
+ module UploadHelper
3
+ def azure_upload_box(options = {}, &block)
4
+ uploader = AzureUploader.new(self, options)
5
+
6
+ content_tag(:div, uploader.form_options) do
7
+ capture(&block)
8
+ end
9
+ end
10
+
11
+ class AzureUploader
12
+ def initialize(view_context, options)
13
+ @options = options.reverse_merge(
14
+ max_file_size: 200.gigabytes,
15
+ sas_url: view_context.azure_direct_upload.sas_sign_url,
16
+ commit_url: view_context.azure_direct_upload.upload_commit_url,
17
+ sas_permissions: "rw",
18
+ sas_expiration: 30.minutes,
19
+ callback_url: nil,
20
+ callback_method: "POST",
21
+ callback_param: "file",
22
+ container: nil,
23
+ max_file_size: nil,
24
+ html: {
25
+ class: "azure-direct-upload",
26
+ id: nil,
27
+ }
28
+ )
29
+ end
30
+
31
+ def form_options
32
+ {
33
+ id: @options[:html][:id],
34
+ class: @options[:html][:class],
35
+ data: {
36
+ sas_url: @options[:sas_url],
37
+ commit_url: @options[:commit_url],
38
+ sas_permissions: @options[:sas_permissions],
39
+ sas_expiration: @options[:sas_expiration],
40
+ callback_url: @options[:callback_url],
41
+ callback_method: @options[:callback_method],
42
+ callback_param: @options[:callback_param],
43
+ max_file_size: @options[:max_file_size],
44
+ container: @options[:container]
45
+ }.reverse_merge(@options[:data] || {})
46
+ }
47
+ end
48
+
49
+ def url
50
+ "#"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,8 @@
1
+ module AzureDirectUpload
2
+ class Railtie < Rails::Railtie
3
+ initializer "railtie.configure_rails_initialization" do |app|
4
+ app.middleware.use JQuery::FileUpload::Rails::Middleware
5
+ end
6
+
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module AzureDirectUpload
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,41 @@
1
+ # desc "Explaining what the task does"
2
+ # task :azure_direct_upload do
3
+ # # Task goes here
4
+ # end
5
+ namespace :azure do
6
+ namespace :direct_upload do
7
+ desc "Setup CORS rules"
8
+ task :setup_cors => :environment do
9
+ blob_service = Azure::Blob::BlobService.new
10
+ props = Azure::Service::StorageServiceProperties.new
11
+
12
+ # Hack so serializer won't output tags like below
13
+ # which trigger syntax error on server.
14
+ #
15
+ # <Logging>
16
+ # <RetentionPolicy/>
17
+ # </Logging>
18
+ props.logging = nil
19
+ props.hour_metrics = nil
20
+ props.minute_metrics = nil
21
+
22
+ # Create a rule
23
+ rule = Azure::Service::CorsRule.new
24
+ rule.allowed_headers = ["*"]
25
+ rule.allowed_methods = ["PUT", "GET", "HEAD", "POST"]
26
+ rule.allowed_origins = ["*"]
27
+ rule.exposed_headers = ["*"]
28
+ rule.max_age_in_seconds = 1800
29
+
30
+ props.cors.cors_rules = [rule]
31
+
32
+ blob_service.set_service_properties(props)
33
+ end
34
+
35
+ desc "Read CORS rules"
36
+ task :read_cors => :environment do
37
+ blob_service = Azure::Blob::BlobService.new
38
+ puts blob_service.get_service_properties.to_yaml
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: azure_direct_upload
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sology
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coffee-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jquery-fileupload-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: azure
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.6'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: azure-contrib
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.12
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.12
83
+ - !ruby/object:Gem::Dependency
84
+ name: addressable
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '2.2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '2.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec-rails
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Upload multiple files directly from client browser to Azure Blob Storage.
126
+ email:
127
+ - contact@sology.eu
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - MIT-LICENSE
133
+ - Rakefile
134
+ - app/assets/javascripts/azure_direct_upload.coffee
135
+ - app/assets/javascripts/azure_direct_upload/application.js
136
+ - app/assets/stylesheets/azure_direct_upload/application.css
137
+ - app/controllers/azure_direct_upload/application_controller.rb
138
+ - app/controllers/azure_direct_upload/sas_controller.rb
139
+ - app/controllers/azure_direct_upload/upload_controller.rb
140
+ - app/helpers/azure_direct_upload/application_helper.rb
141
+ - app/views/layouts/azure_direct_upload/application.html.erb
142
+ - config/routes.rb
143
+ - lib/azure_direct_upload.rb
144
+ - lib/azure_direct_upload/config.rb
145
+ - lib/azure_direct_upload/engine.rb
146
+ - lib/azure_direct_upload/form_helper.rb
147
+ - lib/azure_direct_upload/railtie.rb
148
+ - lib/azure_direct_upload/version.rb
149
+ - lib/tasks/azure_direct_upload_tasks.rake
150
+ homepage: https://github.com/Sology/azure_direct_upload
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.2.2
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Upload multiple files directly from client browser to Azure Blob Storage.
174
+ test_files: []