Method: Fastlane::Actions::AppaloosaAction.upload_on_s3

Defined in:
fastlane/lib/fastlane/actions/appaloosa.rb

.upload_on_s3(file, api_key, store_id, group_ids = '') ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'fastlane/lib/fastlane/actions/appaloosa.rb', line 22

def self.upload_on_s3(file, api_key, store_id, group_ids = '')
  file_name = file.split('/').last
  uri = URI("#{APPALOOSA_SERVER}/upload_services/presign_form")
  params = { file: file_name, store_id: store_id, group_ids: group_ids, api_key: api_key }
  uri.query = URI.encode_www_form(params)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  presign_form_response = http.request(Net::HTTP::Get.new(uri.request_uri))
  json_res = JSON.parse(presign_form_response.body)
  return if error_detected(json_res['errors'])
  s3_sign = json_res['s3_sign']
  path = json_res['path']
  uri = URI.parse(Base64.decode64(s3_sign))
  File.open(file, 'rb') do |f|
    http = Net::HTTP.new(uri.host)
    put = Net::HTTP::Put.new(uri.request_uri)
    put.body = f.read
    put['content-type'] = ''
    http.request(put)
  end
  path
end