Aws-sdk-ruby: How to upload apk file for device farm?

Created on 15 Jul 2015  路  1Comment  路  Source: aws/aws-sdk-ruby

I am trying to create a new upload for DeviceFarm service but still could not.

Script is below

Aws.config.update({
  region: "...",
  credentials: Aws::Credentials.new(...)
})
df_client = Aws::DeviceFarm::Client.new()

upload = df_client.create_upload({
  project_arn: "PROJECT_ARN",
  name: "test.apk",
  content_type: "application/octet-stream",
  type: "ANDROID_APP"
})

This is the response I am getting.

#<struct Aws::DeviceFarm::Types::CreateUploadResult
 upload=
  #<struct Aws::DeviceFarm::Types::Upload
   arn="xxxxxxxxx",
   name="test.apk",
   created=2015-07-15 20:55:38 +0900,
   type="ANDROID_APP",
   status="INITIALIZED",
   url=
    "URL",
   metadata=nil,
   content_type="application/octet-stream",
   message=nil>>

Test binary file is "test.apk" is located in the current directory.

I am not sure if the file test.apk is being uploaded or not. Can anyone tell me how to upload test.apk file?

Thanks

guidance

Most helpful comment

Understood how to upload the file.

While creating upload using create_upload api, pre-signed Amazon S3 URL will be returned in response. And then upload apk on that url. (http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjectPreSignedURLRubySDK.html)

Sample code:

s3_url = "xxxxxxxxx" # got from create_upload response
url = URI.parse(s3_url)
apk_contents = File.open("buggy_app.apk", "rb").read

Net::HTTP.start(url.host) do |http|
  http.send_request("PUT", url.request_uri, apk_contents, {"content-type" => "application/octet-stream"})
end

>All comments

Understood how to upload the file.

While creating upload using create_upload api, pre-signed Amazon S3 URL will be returned in response. And then upload apk on that url. (http://docs.aws.amazon.com/AmazonS3/latest/dev/UploadObjectPreSignedURLRubySDK.html)

Sample code:

s3_url = "xxxxxxxxx" # got from create_upload response
url = URI.parse(s3_url)
apk_contents = File.open("buggy_app.apk", "rb").read

Net::HTTP.start(url.host) do |http|
  http.send_request("PUT", url.request_uri, apk_contents, {"content-type" => "application/octet-stream"})
end
Was this page helpful?
0 / 5 - 0 ratings