Method: GoogleDrive::Session#upload_from_file
- Defined in:
- lib/google_drive/session.rb
#upload_from_file(path, title = nil, params = {}) ⇒ Object
Uploads a local file. Returns a GoogleSpreadsheet::File object.
e.g.
# Uploads a text file and converts to a Google Docs document:
session.upload_from_file("/path/to/hoge.txt")
# Uploads without conversion:
session.upload_from_file("/path/to/hoge.txt", "Hoge", convert: false)
# Uploads with explicit content type:
session.upload_from_file(
"/path/to/hoge", "Hoge", content_type: "text/plain")
# Uploads a text file and converts to a Google Spreadsheet:
session.upload_from_file("/path/to/hoge.csv", "Hoge")
session.upload_from_file(
"/path/to/hoge", "Hoge", content_type: "text/csv")
556 557 558 559 560 561 562 563 564 565 566 567 |
# File 'lib/google_drive/session.rb', line 556 def upload_from_file(path, title = nil, params = {}) # TODO: Add a feature to upload to a folder. file_name = ::File.basename(path) default_content_type = EXT_TO_CONTENT_TYPE[::File.extname(file_name).downcase] || 'application/octet-stream' upload_from_source( path, title || file_name, { content_type: default_content_type }.merge(params) ) end |