Class: Google::Apis::Core::ResumableUploadCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/gcs_stream_upload.rb

Instance Method Summary collapse

Instance Method Details

#send_start_command(client) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gcs_stream_upload.rb', line 6

def send_start_command(client)
  logger.debug { sprintf('Sending upload start command to %s', url) }

  request_header = header.dup
  apply_request_options(request_header)
  request_header[UPLOAD_PROTOCOL_HEADER] = RESUMABLE
  request_header[UPLOAD_COMMAND_HEADER] = START_COMMAND
  if upload_io.respond_to?(:size)
    request_header[UPLOAD_CONTENT_LENGTH] = upload_io.size.to_s
  end
  request_header[UPLOAD_CONTENT_TYPE_HEADER] = upload_content_type

  client.request(method.to_s.upcase,
                 url.to_s, query: nil,
                 body: body,
                 header: request_header,
                 follow_redirect: true)
rescue => e
  raise Google::Apis::ServerError, e.message
end