使用Rest Assured将CSV文件上传到S3 [英] Uploading CSV File to S3 using Rest Assured

查看:333
本文介绍了使用Rest Assured将CSV文件上传到S3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试复制邮递员放送请求,该请求在代码给定的S3位置上上传csv文件的地方.

I am trying to replicate a postman put request where it is uploading a csv file on the S3 location given by a code.

网址类似于 https://us-east-1-e9qpbo283.s3.amazonaws.com/bulk-bucket/a4894e7b-7e42-4fcc-9f84-e7n00db6d581/input/file

,查询参数为{X-Amz-Date=20200226T113914Z, X-Amz-Algorithm=AWS4-HMAC-SHA256, X-Amz-Signature=<Some Signature>, X-Amz-SignedHeaders=content-type%3Bhost, X-Amz-Security-Token=<SOME TOKEN HERE>, X-Amz-Credential=ASIAV7AYOYCBQB4VDGD7%2F20200226%2Fus-east-1%2Fs3%2Faws4_request, X-Amz-Expires=3600}

但是我总是收到400个错误的请求.该请求也不需要任何其他身份验证令牌.有人可以帮我弄这个吗.

But I am always getting 400 bad request. The request also doesn't require any other auth token. Can someone help me with this.

我已经访问过并尝试了链接

I have already visited and tried the links

使用Rest Assured multipart将文件上传到S3

https://groups.google.com/d/topic/rest -assured/MPzbiozclqg

https://github.com/rest-assured/rest-assured/issues/627

我的代码就像

File uploadFile = new File("/home/beast/Downloads/locations.csv");

RequestSpecification request = given().urlEncodingEnabled(false).              
 config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false)))
                .multiPart("file", uploadFile, "csv");
Response r = request.put(URL);

PS:错误是签名不匹配.

推荐答案

由于您将CSV作为二进制文件传递到正文中,因此您可以打开该文件并将其传递到正文中,如以下示例所示:

Since you are passing the CSV as a binary file in the body you can just open the file and pass it in the body like in below example:

  RestAssured.urlEncodingEnabled = false;
    File uploadFile = new File("COMPLETE_FILE_PATH");
    Response response = given().contentType("text/csv")              .config(RestAssured.config().encoderConfig(EncoderConfig.encoderConfig().appendDefaultContentCharsetToContentTypeIfUndefined(false)))
                    .body(uploadFile)
                    .when()
                    .put(uploadUrl)
                    .then().extract().response();

这篇关于使用Rest Assured将CSV文件上传到S3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆