Class: Bkblz::V1::UploadFileRequest
- Defined in:
- lib/bkblz/v1/upload_file.rb
Constant Summary collapse
- REQUIRED_HEADERS =
{ :"Authorization" => nil, :"X-Bz-File-Name" => nil, :"Content-Type" => "b2/x-auto", :"Content-Length" => nil, :"X-Bz-Content-Sha1" => nil }
Instance Method Summary collapse
- #build_request(session) ⇒ Object
-
#initialize(upload_auth, body, file_name, content_type = nil, last_modified_millis = nil, **bz_info) ⇒ UploadFileRequest
constructor
A new instance of UploadFileRequest.
Methods inherited from Request
response_class, #send, url_suffix
Constructor Details
#initialize(upload_auth, body, file_name, content_type = nil, last_modified_millis = nil, **bz_info) ⇒ UploadFileRequest
Returns a new instance of UploadFileRequest.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bkblz/v1/upload_file.rb', line 24 def initialize(upload_auth, body, file_name, content_type=nil, last_modified_millis=nil, **bz_info) unless last_modified_millis # Recommended https://www.backblaze.com/b2/docs/b2_upload_file.html bz_info["src_last_modified_millis"] = last_modified_millis end raise TooManyBzInfoHeadersError, bz_info_headers if bz_info.size > 10 @upload_url = upload_auth.upload_url @body = body.is_a?(IO) ? body.read : body @headers = REQUIRED_HEADERS.dup bz_info.each do |k,v| @headers["X-Bz-Info-#{k.to-s}".to_sym] = v end @headers[:"Authorization"] = upload_auth. @headers[:"X-Bz-File-Name"] = file_name @headers[:"Content-Length"] = @body.size @headers[:"X-Bz-Content-Sha1"] = Digest::SHA1.hexdigest @body end |
Instance Method Details
#build_request(session) ⇒ Object
45 46 47 |
# File 'lib/bkblz/v1/upload_file.rb', line 45 def build_request(session) session.create_post @upload_url, @body, @headers end |