def upload(api_method, url, options = {})
        mime_type = ::MIME::Types.type_for(options[:media]).first.to_s
        file = File.read(options.delete(:media))

        options[:body][:mimeType] = mime_type
        options[:headers] = (options[:headers] || {}).merge({'X-Upload-Content-Type' => mime_type})

        response = request(api_method, url, options)

        options[:body] = file
        options[:headers].delete('X-Upload-Content-Type')
        options[:headers].merge!({'Content-Type' => mime_type, 'Content-Length' => file.bytesize.to_s})

        request(:put, response.headers['Location'], options)
      end
def upload(api_method, url, options = {})
        mime_type = ::MIME::Types.type_for(options[:media]).first.to_s
        file = File.read(options.delete(:media))

        options[:body][:mimeType] = mime_type
        options[:headers] = (options[:headers] || {}).merge({'X-Upload-Content-Type' => mime_type})

        response = request(api_method, url, options)

        options[:body] = file
        options[:headers].delete('X-Upload-Content-Type')
        options[:headers].merge!({'Content-Type' => mime_type, 'Content-Length' => file.bytesize.to_s})

        request(:put, response.headers['Location'], options)
      end
Build a resumable upload request that then makes POST and PUT requests with the correct
 headers for each request.

 The initial POST request initiates the upload process, passing the metadata for the file.
 The response from the API includes a Location header telling us where to actually send the
 media we want uploaded. The subsequent PUT request sends the media itself to the API.