class FileConvert::Upload

Constants

DEFAULT_PARAMS

Attributes

file[R]

Public Class Methods

new(client, file_path, mime_type) click to toggle source

Uploads file to Google Drive

@param [FileConvert::Client] client @param [String] file_path

File to upload

@param [String] mime_type

Source mime_type of upload-file

@return [FileConvert::File] New File object without conversions yet

# File lib/file_convert/upload.rb, line 21
def initialize(client, file_path, mime_type)
  @client = client
  @file_path = file_path
  @mime_type = mime_type

  uploaded_file = client.execute(
    api_method: client.drive.files.insert,
    body_object: touch_file,
    media: upload_io,
    parameters: DEFAULT_PARAMS
  )

  @file = FileConvert::File.new(uploaded_file)
end

Private Instance Methods

touch_file() click to toggle source
# File lib/file_convert/upload.rb, line 38
def touch_file
  @client.drive.files.insert.request_schema.new(
    'title' => SecureRandom.uuid,
    'description' => 'FileConvert Conversion-File',
    'mimeType' => @mime_type
  )
end
upload_io() click to toggle source
# File lib/file_convert/upload.rb, line 46
def upload_io
  Google::APIClient::UploadIO.new(@file_path, @mime_type)
end