carrierwave-azure 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +1 -0
- data/carrierwave-azure.gemspec +23 -0
- data/lib/carrierwave/azure/version.rb +5 -0
- data/lib/carrierwave/storage/azure.rb +109 -0
- data/lib/carrierwave-azure.rb +13 -0
- data/spec/carrierwave/storage/azure_spec.rb +95 -0
- data/spec/carrierwave-azure_spec.rb +13 -0
- data/spec/environment.rb.sample +7 -0
- data/spec/spec_helper.rb +9 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fecd5b8613590588dcb0e03fba595842ae08a620
|
4
|
+
data.tar.gz: 58a6c177c57c4aa4342b3a77040a820350291ac0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d79615674c9abc497304c840ad16fcda17a5bd10c4735c96f49da971448fe7266a48f1936641ada4df5acae17b2cedf724e6d990005883498eca620a76a95308
|
7
|
+
data.tar.gz: 338f7aa4b955888938691e2774f97aee1f910ec64ef04de5e4c2a97819949c6223184addc7754b4a3fc30f9937b9fdd0b17deabf690fec0b30ba31797a096a87
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 heathrow, inc.
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Carrierwave::Azure
|
2
|
+
|
3
|
+
Windows Azure blob storage support for [CarrierWave](https://github.com/carrierwaveuploader/carrierwave)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'carrierwave-azure'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
First configure CarrierWave with your Azure storage credentials
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
CarrierWave.configure do |config|
|
21
|
+
config.azure_credentials = {
|
22
|
+
storage_account_name: 'YOUR STORAGE ACCOUNT NAME',
|
23
|
+
storage_access_key: 'YOUR STORAGE ACCESS KEY'
|
24
|
+
}
|
25
|
+
config.azure_container = 'YOUR CONTAINER NAME'
|
26
|
+
config.azure_host = 'YOUR CDN HOST' # optional
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
And then in your uploader, set the storage to `:azure`
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
class ExampleUploader < CarrierWave::Uploader::Base
|
34
|
+
storage :azure
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
In order to run the integration specs you will need to configure some environment variables.
|
41
|
+
A sample file is provided as `spec/environment.rb.sample`.
|
42
|
+
Copy it over and plug in the appropriate values.
|
43
|
+
|
44
|
+
```bash
|
45
|
+
cp spec/environment.rb.sample spec/environment.rb
|
46
|
+
```
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'carrierwave/azure/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'carrierwave-azure'
|
7
|
+
gem.version = Carrierwave::Azure::VERSION
|
8
|
+
gem.authors = ['Yusuke Shibahara']
|
9
|
+
gem.email = ['yusuke.shibahara@heathrow.co.jp']
|
10
|
+
gem.summary = %q{Windows Azure blob storage support for CarrierWave}
|
11
|
+
gem.description = %q{Allows file upload to Azure with the officail sdk}
|
12
|
+
gem.homepage = 'https://github.com/unosk/carrierwave-azure'
|
13
|
+
gem.license = 'MIT'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.test_files = gem.files.grep(%r{^rspec})
|
17
|
+
gem.require_paths = ['lib']
|
18
|
+
|
19
|
+
gem.add_dependency 'carrierwave'
|
20
|
+
gem.add_dependency 'azure'
|
21
|
+
|
22
|
+
gem.add_development_dependency 'rspec'
|
23
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'azure'
|
2
|
+
|
3
|
+
module CarrierWave
|
4
|
+
module Storage
|
5
|
+
class Azure < Abstract
|
6
|
+
def store!(file)
|
7
|
+
azure_file = CarrierWave::Storage::Azure::File.new(uploader, connection, uploader.store_path)
|
8
|
+
azure_file.store!(file)
|
9
|
+
azure_file
|
10
|
+
end
|
11
|
+
|
12
|
+
def retrieve!(identifer)
|
13
|
+
CarrierWave::Storage::Azure::File.new(uploader, connection, uploader.store_path(identifer))
|
14
|
+
end
|
15
|
+
|
16
|
+
def connection
|
17
|
+
@connection ||= begin
|
18
|
+
uploader.azure_credentials.map do |key, val|
|
19
|
+
::Azure.config.send("#{key}=", val)
|
20
|
+
end unless uploader.azure_credentials.nil?
|
21
|
+
::Azure::BlobService.new
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class File
|
26
|
+
attr_reader :path
|
27
|
+
|
28
|
+
def initialize(uploader, connection, path)
|
29
|
+
@uploader = uploader
|
30
|
+
@connection = connection
|
31
|
+
@path = path
|
32
|
+
end
|
33
|
+
|
34
|
+
def store!(file)
|
35
|
+
@content = file.read
|
36
|
+
@content_type = file.content_type
|
37
|
+
@connection.create_block_blob @uploader.azure_container, @path, @content
|
38
|
+
true
|
39
|
+
end
|
40
|
+
|
41
|
+
def url(options = {})
|
42
|
+
path = ::File.join @uploader.azure_container, @path
|
43
|
+
if @uploader.azure_host
|
44
|
+
"#{@uploader.azure_host}/#{path}"
|
45
|
+
else
|
46
|
+
@connection.generate_uri(path).to_s
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def read
|
51
|
+
content
|
52
|
+
end
|
53
|
+
|
54
|
+
def content_type
|
55
|
+
@content_type = blob.properties[:content_type] if @content_type.nil? && blob.persent?
|
56
|
+
@content_type
|
57
|
+
end
|
58
|
+
|
59
|
+
def content_type=(new_content_type)
|
60
|
+
@content_type = new_content_type
|
61
|
+
end
|
62
|
+
|
63
|
+
def exitst?
|
64
|
+
blob.nil?
|
65
|
+
end
|
66
|
+
|
67
|
+
def size
|
68
|
+
blob.properties[:content_length] unless blob.nil?
|
69
|
+
end
|
70
|
+
|
71
|
+
def filename
|
72
|
+
URI.decode(url).gsub(/.*\/(.*?$)/, '\1')
|
73
|
+
end
|
74
|
+
|
75
|
+
def extension
|
76
|
+
@path.split('.').last
|
77
|
+
end
|
78
|
+
|
79
|
+
def delete
|
80
|
+
begin
|
81
|
+
@connection.delete_blob @uploader.azure_container, @path
|
82
|
+
true
|
83
|
+
rescue ::Azure::Core::Http::HTTPError
|
84
|
+
false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def blob
|
91
|
+
load_content if @blob.nil?
|
92
|
+
@blob
|
93
|
+
end
|
94
|
+
|
95
|
+
def content
|
96
|
+
load_content if @content.nil?
|
97
|
+
@content
|
98
|
+
end
|
99
|
+
|
100
|
+
def load_content
|
101
|
+
@blob, @content = begin
|
102
|
+
@connection.get_blob @uploader.azure_container, @path
|
103
|
+
rescue ::Azure::Core::Http::HTTPError
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'carrierwave'
|
2
|
+
require 'carrierwave/azure/version'
|
3
|
+
require 'carrierwave/storage/azure'
|
4
|
+
|
5
|
+
class CarrierWave::Uploader::Base
|
6
|
+
add_config :azure_credentials
|
7
|
+
add_config :azure_host
|
8
|
+
add_config :azure_container
|
9
|
+
|
10
|
+
configure do |config|
|
11
|
+
config.storage_engines[:azure] = 'CarrierWave::Storage::Azure'
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'open-uri'
|
4
|
+
|
5
|
+
describe CarrierWave::Storage::Azure do
|
6
|
+
class TestUploader < CarrierWave::Uploader::Base
|
7
|
+
storage :azure
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:uploader) { TestUploader.new }
|
11
|
+
let(:storage) { CarrierWave::Storage::Azure.new uploader }
|
12
|
+
|
13
|
+
shared_examples_for 'an expected return value' do
|
14
|
+
it 'should have a path' do
|
15
|
+
expect(@azure_file.path).to eq expect_path
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should have a url' do
|
19
|
+
url = @azure_file.url
|
20
|
+
expect(url).to match /^https?:\/\//
|
21
|
+
expect(open(url).read).to eq expect_content
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have a content' do
|
25
|
+
expect(@azure_file.read).to eq expect_content
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have a content_type' do
|
29
|
+
expect(@azure_file.content_type).to eq expect_content_type
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should have a size' do
|
33
|
+
expect(@azure_file.size).to eq expect_size
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should have a filename' do
|
37
|
+
expect(@azure_file.filename).to eq expect_filename
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should have an extension' do
|
41
|
+
expect(@azure_file.extension).to eq expect_extension
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should be deletable' do
|
45
|
+
@azure_file.delete
|
46
|
+
expect{open @azure_file.url}.to raise_error OpenURI::HTTPError
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#store!' do
|
51
|
+
before do
|
52
|
+
uploader.stub!(:store_path).and_return('test/dummy1.png')
|
53
|
+
tempfile = Tempfile.new 'test.jpg'
|
54
|
+
open(tempfile.path, 'w') do |f|
|
55
|
+
f.print '1234567890'
|
56
|
+
end
|
57
|
+
@azure_file = storage.store! CarrierWave::SanitizedFile.new(
|
58
|
+
tempfile: tempfile,
|
59
|
+
filename: 'test.jpg',
|
60
|
+
content_type: 'image/png'
|
61
|
+
)
|
62
|
+
end
|
63
|
+
|
64
|
+
it_should_behave_like 'an expected return value' do
|
65
|
+
let(:expect_path) { 'test/dummy1.png' }
|
66
|
+
let(:expect_content) { '1234567890' }
|
67
|
+
let(:expect_content_type) { 'image/png' }
|
68
|
+
let(:expect_size) { 10 }
|
69
|
+
let(:expect_filename) { 'dummy1.png' }
|
70
|
+
let(:expect_extension) { 'png' }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#retrieve' do
|
75
|
+
before do
|
76
|
+
uploader.stub!(:store_path).and_return('test/dummy2.png')
|
77
|
+
storage.connection.create_block_blob(
|
78
|
+
uploader.azure_container,
|
79
|
+
'test/dummy2.png',
|
80
|
+
'0123456789ABCDEF',
|
81
|
+
content_type: 'text/plain'
|
82
|
+
)
|
83
|
+
@azure_file = storage.retrieve! 'test/dummy2.png'
|
84
|
+
end
|
85
|
+
|
86
|
+
it_should_behave_like 'an expected return value' do
|
87
|
+
let(:expect_path) { 'test/dummy2.png' }
|
88
|
+
let(:expect_content_type) { 'text/plain' }
|
89
|
+
let(:expect_content) { "0123456789ABCDEF" }
|
90
|
+
let(:expect_size) { 16 }
|
91
|
+
let(:expect_filename) { 'dummy2.png' }
|
92
|
+
let(:expect_extension) { 'png' }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CarrierWave::Uploader::Base do
|
4
|
+
it 'should define azure as a storage engine' do
|
5
|
+
described_class.storage_engines[:azure].should == 'CarrierWave::Storage::Azure'
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should define azure options' do
|
9
|
+
should respond_to(:azure_credentials)
|
10
|
+
should respond_to(:azure_container)
|
11
|
+
should respond_to(:azure_host)
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-azure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yusuke Shibahara
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: carrierwave
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: azure
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Allows file upload to Azure with the officail sdk
|
56
|
+
email:
|
57
|
+
- yusuke.shibahara@heathrow.co.jp
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- carrierwave-azure.gemspec
|
69
|
+
- lib/carrierwave-azure.rb
|
70
|
+
- lib/carrierwave/azure/version.rb
|
71
|
+
- lib/carrierwave/storage/azure.rb
|
72
|
+
- spec/carrierwave-azure_spec.rb
|
73
|
+
- spec/carrierwave/storage/azure_spec.rb
|
74
|
+
- spec/environment.rb.sample
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
homepage: https://github.com/unosk/carrierwave-azure
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.0.0
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Windows Azure blob storage support for CarrierWave
|
100
|
+
test_files: []
|