Method: Morpheus::DeploymentsInterface#upload_file

Defined in:
lib/morpheus/api/deployments_interface.rb

#upload_file(deployment_id, id, local_file, destination, params = {}) ⇒ Object

upload a file without multipart local_file is the full absolute local filename destination should be the full remote file path, including the file name.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/morpheus/api/deployments_interface.rb', line 39

def upload_file(deployment_id, id, local_file, destination, params={})
  if destination.empty? || destination == "/" || destination == "." || destination.include?("../")
    raise "#{self.class}.upload_file() passed a bad destination: '#{destination}'"
  end
  # url = "#{@base_url}/#{base_path}/#{deployment_id}/versions/#{id}/files"
  url = "#{base_path}/#{deployment_id}/versions/#{id}/files"
  if !destination.to_s.empty?
    url += "/#{destination}"
  end
  # use URI to escape path
  uri = URI.parse(url)
  url = uri.path
  # params[:filename] = File.basename(destination)
  if !local_file.kind_of?(File)
    local_file = File.new(local_file, 'rb')
  end
  payload = local_file
  headers = {'Content-Type' => 'application/octet-stream'}
  headers['Content-Length'] = local_file.size # File.size(local_file)
  execute(method: :post, url: url, headers: headers, payload: payload, params: params, timeout: 172800)
end