将文件上传到 AWS Device Farm

Posted

技术标签:

【中文标题】将文件上传到 AWS Device Farm【英文标题】:Upload file to AWS Device Farm 【发布时间】:2018-03-02 13:42:12 【问题描述】:

我正在尝试使用 python + boto3 在设备场中创建上传(上传测试或应用程序)。方法“create_upload”工作正常,因为它返回一个上传 arn 和 url 上传到它。

当我尝试使用请求将文件上传到此 URL 时出现错误:

<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><AWSAccessKeyId>AKIAJV4C3CWPBUMBC3GA</AWSAccessKeyId><StringToSign>AWS4-HMAC-SHA256

我的代码:

response = client.create_upload(
  projectArn=df_project,
  name="test.zip",
  type="APPIUM_JAVA_TESTNG_TEST_PACKAGE",
  contentType='application/octet-stream'
)
test_url = response["upload"]["url"]
files = 'upload_file': open('/tmp/test.zip','rb')
r = requests.post(test_url, files=files, data=)

我也尝试使用 curl 和 requests.post 将文件传递给数据 属性:

r = requests.put(test_url, data=open("/tmp/test.zip", "rb").read())
print(r.text)

cmd = "curl --request PUT --upload-file /tmp/test.zip \""+test_url+"\""
result = subprocess.call(cmd, shell=True)
print(result)

【问题讨论】:

【参考方案1】:

我以前在过去的项目中这样做过。这是我如何做到的代码sn-p:

创建一个新的上传

#http://boto3.readthedocs.io/en/latest/reference/services/devicefarm.html#DeviceFarm.Client.create_upload
print('Creating the upload presigned url')
response = client.create_upload(projectArn=args.projectARN,name=str(args.testPackageZip),type='APPIUM_WEB_JAVA_TESTNG_TEST_PACKAGE')
#create the s3 bucket to store the upload test suite
uploadArn = response['upload']['arn']
preSignedUrl = response['upload']['url']
print('uploadArn: ' + uploadArn + '\n')
print('pre-signed url: ' + preSignedUrl + '\n')

#print the status of the upload
#http://boto3.readthedocs.io/en/latest/reference/services/devicefarm.html#DeviceFarm.Client.get_upload
status = client.get_upload(arn=uploadArn)
print("S3 Upload Bucket Status: " + status['upload']['status'] + '\n')

print("Uploading file...")
#open the file and make payload
payload = 'file':open(args.testPackageZip,'rb')
#try and perform the upload
r = requests.put(url = preSignedUrl,files = payload)
#print the response code back
print(r)

希望有帮助

【讨论】:

【参考方案2】:

我在 AWS Device Farm 工作。当某些请求参数与用于签署 URL 的参数不匹配时,就会出现此问题。我看到这个问题的次数,它与内容类型有关。我建议不要在 CreateUpload 请求中传递它。如果您确实通过了它,那么您还需要在进行 PUT 调用时将其作为请求标头包含在内。

【讨论】:

以上是关于将文件上传到 AWS Device Farm的主要内容,如果未能解决你的问题,请参考以下文章

Amazon Device Farm 的 KIF .xctest 目录

将 AWS Device Farm 与 JUnit 5 结合使用

为 AWS Device Farm 构建 XCTest UI 测试

AWS Device Farm 的 XCTest 单元和 UI 测试

通过 AWS SDK for Go 在 Device Farm 中上传的 Android 应用程序从未从 INITIALIZED 更改状态

无法在 iOS Appium 测试(AWS Device Farm)上切换到 WebView 上下文