Class: CarrierWave::Storage::Azure::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::Azure::File
- Defined in:
- lib/carrierwave/storage/azure.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #content_type ⇒ Object
- #content_type=(new_content_type) ⇒ Object
- #delete ⇒ Object
- #exist? ⇒ Boolean
- #extension ⇒ Object
- #filename ⇒ Object
-
#initialize(uploader, connection, path) ⇒ File
constructor
A new instance of File.
- #read ⇒ Object
- #size ⇒ Object
- #store!(file) ⇒ Object
- #url(options = {}) ⇒ Object
Constructor Details
#initialize(uploader, connection, path) ⇒ File
Returns a new instance of File.
28 29 30 31 32 |
# File 'lib/carrierwave/storage/azure.rb', line 28 def initialize(uploader, connection, path) @uploader = uploader @connection = connection @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
26 27 28 |
# File 'lib/carrierwave/storage/azure.rb', line 26 def path @path end |
Instance Method Details
#content_type ⇒ Object
67 68 69 70 |
# File 'lib/carrierwave/storage/azure.rb', line 67 def content_type @content_type = blob.properties[:content_type] if @content_type.nil? && !blob.nil? @content_type end |
#content_type=(new_content_type) ⇒ Object
72 73 74 |
# File 'lib/carrierwave/storage/azure.rb', line 72 def content_type=(new_content_type) @content_type = new_content_type end |
#delete ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/carrierwave/storage/azure.rb', line 92 def delete begin @connection.delete_blob @uploader.azure_container, @path true rescue ::Azure::Core::Http::HTTPError false end end |
#exist? ⇒ Boolean
76 77 78 |
# File 'lib/carrierwave/storage/azure.rb', line 76 def exist? blob.nil? end |
#extension ⇒ Object
88 89 90 |
# File 'lib/carrierwave/storage/azure.rb', line 88 def extension @path.split('.').last end |
#filename ⇒ Object
84 85 86 |
# File 'lib/carrierwave/storage/azure.rb', line 84 def filename URI.decode(url).gsub(/.*\/(.*?$)/, '\1') end |
#read ⇒ Object
63 64 65 |
# File 'lib/carrierwave/storage/azure.rb', line 63 def read content end |
#size ⇒ Object
80 81 82 |
# File 'lib/carrierwave/storage/azure.rb', line 80 def size blob.properties[:content_length] unless blob.nil? end |
#store!(file) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/carrierwave/storage/azure.rb', line 34 def store!(file) @content_type = file.content_type file_to_send = ::File.open(file.file, 'rb') block_id = 0 blocks = [] until file_to_send.eof? block_id += 1 @content = file_to_send.read 4194304 # Send 4MB chunk @connection.create_blob_block @uploader.azure_container, @path, block_id.to_s, @content blocks << block_id.to_s end # Commit block blobs @connection.commit_blob_blocks @uploader.azure_container, @path, blocks, :blob_content_type => @content_type true end |
#url(options = {}) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/carrierwave/storage/azure.rb', line 54 def url( = {}) path = ::File.join @uploader.azure_container, @path if @uploader.asset_host "#{@uploader.asset_host}/#{path}" else @connection.generate_uri(path).to_s end end |