我正在尝试使用从服务器端(用 python 编码)应用程序生成的签名 URL 将视频文件从 android 应用程序上传到 S3 服务器中的存储桶。我们正在向签名的 URL 发出 PUT 请求,但我们得到了
connection reset by peer exception.
但是当我在 POSTMAN REST CLIENT 上尝试相同的 URL 时,会收到一条成功消息。任何帮助将不胜感激。
我正在尝试使用预先签名的URL将文件上传到Amazon的S3。我从生成URL的服务器获取URL,并将其作为JSON对象的一部分发送给我。我将URL作为字符串获取,如下所示:
不幸的是,当我将其传递给Retrofit2时,它修改了String并试图将其制成URL。我已经设置好encoding=true了,可以解决大多数问题,但不能完全解决。我知道字符串按原样工作。我在邮递员中尝试过并获得成功的回应。
1st我尝试仅将String(除了我作为baseUrl剪切的东西)整体放入Path
public interface UpdateImageInterface {
@PUT("{url}")
Call<Void> updateImage(@Path(value="url", encoded=true) String url, Body RequestBody image);
}
Run Code Online (Sandbox Code Playgroud)
调用代码:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://com-example-mysite.s3-us-east-1.amazonaws.com/userFolder/")
.build();
UpdateImageInterface imageInterface = retrofit.create(UpdateImageInterface.class);
// imageUrl is "ImageName..."
Call<Void> call = imageInterface.updateImage(imageUrl, requestFile);
Run Code Online (Sandbox Code Playgroud)
除“?”外,此方法大部分有效 (在“ ImageName”之后)转换为“%3F”。这会导致请求错误/ 400。
我的下一个尝试是使用Retrofit2创建查询,然后将整个String(包含多个查询)转储到查询中。
public interface UpdateImageInterface {
@PUT("ImageName")
Call<Void> updateProfilePhoto(@Query(value="X-Amz-Security-Token", encoded = true) String token, @Body RequestBody image);
}
Run Code Online (Sandbox Code Playgroud)
调用代码:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://com-example-mysite.s3-us-east-1.amazonaws.com/userFolder/") …Run Code Online (Sandbox Code Playgroud)