Method: Morpheus::StorageProvidersInterface#upload_file
- Defined in:
- lib/morpheus/api/storage_providers_interface.rb
#upload_file(id, local_file, destination, params = {}) ⇒ Object
upload a file without multipart
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/morpheus/api/storage_providers_interface.rb', line 52 def upload_file(id, local_file, destination, params={}) # puts "upload_file #{local_file} to destination #{destination}" # destination should be the full filePath, but the api looks like directory?filename= path = destination.to_s.squeeze("/") if !path || path == "" || path == "/" || path == "." raise "#{self.class}.upload_file() passed a bad destination: '#{destination}'" end if path[0].chr == "/" path = path[1..-1] end path_chunks = path.split("/") filename = path_chunks.pop safe_dirname = path_chunks.collect {|it| CGI::escape(it) }.join("/") # filename = File.basename(destination) # dirname = File.dirname(destination) # if filename == "" || filename == "/" # filename = File.basename(local_file) # end url = "#{@base_url}/api/storage/buckets/#{CGI::escape(id.to_s)}" + "/files/#{safe_dirname}".squeeze('/') headers = { :params => params, :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/octet-stream'} headers[:params][:filename] = filename # File.basename(destination) if !local_file.kind_of?(File) local_file = File.new(local_file, 'rb') end payload = local_file headers['Content-Length'] = local_file.size # File.size(local_file) execute(method: :post, url: url, headers: headers, payload: payload) end |