Class: FileConvert::Upload

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

Constant Summary collapse

DEFAULT_PARAMS =
{
  'uploadType' => 'multipart',
  'convert' => true,
  'alt' => 'json'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, file_path, mime_type) ⇒ FileConvert::File

Uploads file to Google Drive

Parameters:

  • client (FileConvert::Client)
  • file_path (String)

    File to upload

  • mime_type (String)

    Source mime_type of upload-file



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



9
10
11
# File 'lib/file_convert/upload.rb', line 9

def file
  @file
end