当我尝试使用aws java sdk将文件上传到s3时,我收到有关InvalidRedirectLocation的错误。
if (estado.equals("inicioR")) {
polylinePaths.add(mMap.addPolyline(polylineOptions));
} else if (estado.equals("finR")){
// Get the polyline that you want to remove from the list
// by the index. Here for the example the index is 1
int index = 1;
Polyline polyline = polylinePaths.get(index);
// you need to check for IndexOutOfBoundsException.
// In this example code, assume that IndexOutOfBoundsException never happened.
// remove the polyline from the map.
polyline.remove();
// then remove from the list.
polylinePaths.remove(index);
}
以下是我的代码中的代码段。
Exception in thread "main" com.amazonaws.services.s3.model.AmazonS3Exception:
The website redirect location must have a prefix of 'http://' or 'https://' or '/'.
(Service: Amazon S3; Status Code: 400; Error Code: InvalidRedirectLocation;
Request ID: E801AFDA2A22A20E; S3 Extended Request ID: AAlLOlndWp2dAAA56Vlxs+ZTLCK/
HHaPv/ySaqjIAAAO4wv8qzkm17A7o7YOrtmOx4YJO+yfAAA=), S3 Extended Request ID: LAlAO
lndAp2dAAPA6Vlxs+ZTLCK/AAaPv/ySaqjIAAAO4wv8qzkm17b7o7AOrtmOx4AAO+yflAA=
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1630)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1302)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1056)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:717)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:699)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:667)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:649)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:513)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4330)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:4277)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1750)
at awsTest.main(awsTest.java:67)
我可以列出存储桶中的文件并将文件从一个存储桶复制到另一个存储桶,但我无法上传文件。知道为什么吗?
答案 0 :(得分:1)
我将文件的位置作为字符串传递给putObject函数,我需要使用文件类,因此以下代码解决了我的问题。
String s3Bucket = "test_bucket";
String s3FileName = "test_file.txt";
String localFileName = "C:\\Users\\ABC\\Desktop\\test_file.txt";
File file = new File(localFileName);
s3.putObject(new PutObjectRequest(s3Bucket, s3FileName, file ));