Method: Azure::Storage::Blob#get_blob

Defined in:
lib/azure/storage/blob/blob.rb

#get_blob(container, blob, options = {}) ⇒ Object

Public: Reads or downloads a blob from the system, including its metadata and properties.

Attributes

  • container - String. The container name.

  • blob - String. The blob name.

  • options - Hash. Optional parameters.

Options

Accepted key/value pairs in options parameter are:

  • :start_range - Integer. Position of first byte of first page. (optional)

  • :end_range - Integer. Position of last byte of of last page. (optional)

  • :snapshot - String. An opaque DateTime value that specifies the blob snapshot to

    retrieve information from. (optional)
    
  • :get_content_md5 - Boolean. Return the MD5 hash for the range. This option only valid if

    start_range and end_range are specified. (optional)
    
  • :timeout - Integer. A timeout in seconds.

  • :request_id - String. Provides a client-generated, opaque value with a 1 KB character limit that is recorded

    in the analytics logs when storage analytics logging is enabled.
    
  • :location_mode - LocationMode. Specifies the location mode used to decide

    which location the request should be sent to.
    
  • :if_modified_since - String. A DateTime value. Specify this conditional header to get the blob

    only if the blob has been modified since the specified date/time. If the blob has not been modified,
    the Blob service returns status code 412 (Precondition Failed).
    
  • :if_unmodified_since - String. A DateTime value. Specify this conditional header to get the blob

    only if the blob has not been modified since the specified date/time. If the blob has been modified,
    the Blob service returns status code 412 (Precondition Failed).
    
  • :if_match - String. An ETag value. Specify an ETag value for this conditional header to get the blob

    only if the blob's ETag value matches the value specified. If the values do not match,
    the Blob service returns status code 412 (Precondition Failed).
    
  • :if_none_match - String. An ETag value. Specify an ETag value for this conditional header to get the blob

    only if the blob's ETag value does not match the value specified. If the values are identical,
    the Blob service returns status code 412 (Precondition Failed).
    
  • :lease_id - String. If this header is specified, the operation will be performed only if both of the

    following conditions are met:
     - The blob's lease is currently active.
     - The lease ID specified in the request matches that of the blob.
    If this header is specified and both of these conditions are not met, the request will fail
    and the Get Blob operation will fail with status code 412 (Precondition Failed).
    

See msdn.microsoft.com/en-us/library/azure/dd179440.aspx

Returns a blob and the blob body



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/azure/storage/blob/blob.rb', line 89

def get_blob(container, blob, options = {})
  query = {}
  StorageService.with_query query, "snapshot", options[:snapshot]
  StorageService.with_query query, "timeout", options[:timeout] if options[:timeout]

  options[:request_location_mode] = Azure::Storage::Common::RequestLocationMode::PRIMARY_OR_SECONDARY
  uri = blob_uri(container, blob, query, options)

  headers = {}
  options[:start_range] = 0 if options[:end_range] && (not options[:start_range])
  if options[:start_range]
    StorageService.with_header headers, "x-ms-range", "bytes=#{options[:start_range]}-#{options[:end_range]}"
    StorageService.with_header headers, "x-ms-range-get-content-md5", "true" if options[:get_content_md5]
  end
  add_blob_conditional_headers options, headers
  headers["x-ms-lease-id"] = options[:lease_id] if options[:lease_id]

  response = call(:get, uri, nil, headers, options)
  result = Serialization.blob_from_headers(response.headers)
  result.name = blob unless result.name

  return result, response.body
end