Class: SimpleGdrive::Uploader
- Defined in:
- lib/simple_gdrive/uploader.rb
Overview
Uploads file
Constant Summary collapse
- FOLDER_MIME_TYPE =
'application/vnd.google-apps.folder'.freeze
- OPTIONS =
{retries: 5}.freeze
Instance Method Summary collapse
- #call(full_filename, upload_source, content_type:, mime_type: nil) ⇒ Object
-
#initialize(base_folder_id:) ⇒ Uploader
constructor
A new instance of Uploader.
Constructor Details
#initialize(base_folder_id:) ⇒ Uploader
Returns a new instance of Uploader.
7 8 9 |
# File 'lib/simple_gdrive/uploader.rb', line 7 def initialize(base_folder_id:) @base_folder_id = base_folder_id end |
Instance Method Details
#call(full_filename, upload_source, content_type:, mime_type: nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/simple_gdrive/uploader.rb', line 11 def call(full_filename, upload_source, content_type:, mime_type: nil) names = full_filename.split('/') filename = names.pop parent_id = find_folder(names) = {name: filename, parents: [parent_id]} [:mime_type] = mime_type if mime_type file = service.create_file( , upload_source: upload_source, content_type: content_type, options: OPTIONS ) {id: file.id, parent_id: parent_id} end |