class MyBitcasa::Upload
Public Class Methods
new(dest_path)
click to toggle source
# File lib/my_bitcasa/upload.rb, line 8 def initialize(dest_path) @dest_path = dest_path end
Public Instance Methods
upload(src_path, content_type: nil, filename: nil)
click to toggle source
# File lib/my_bitcasa/upload.rb, line 12 def upload(src_path, content_type: nil, filename: nil) # check src_path unless File.file?(src_path) raise Errno::ENOENT, "No such file - #{src_path}" end # check content_type unless content_type mime_type = MIME::Types.type_for(src_path).first if mime_type content_type = mime_type.to_s else content_type = 'application/octet-stream' end end # multipart connection res = multipart_connection.post do |req| req.url "/files" req.params = { path: @dest_path, } req.body = { file: Faraday::UploadIO.new(src_path, content_type, filename) } end BitcasaFile.new(res.body.first) end