gpt4 book ai didi

java - AWS Java putObject InvalidRedirectLocation

转载 作者:行者123 更新时间:2023-11-30 06:17:15 29 4
gpt4 key购买 nike

当我尝试使用 aws java sdk 将文件上传到 s3 时,收到有关 InvalidRedirectLocation 的错误。

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)

这是我的代码片段。

String s3Bucket = "test_bucket";
String s3FileName = "test_file.txt";
String localFileName = "C:\\Users\\ABC\\Desktop\\test_file.txt";

s3.putObject(new PutObjectRequest(s3Bucket, s3FileName, localFileName));

我可以列出存储桶中的文件并将文件从一个存储桶复制到另一个存储桶,但无法上传文件。知道为什么吗?

最佳答案

我将文件的位置作为字符串传递给 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 ));

关于java - AWS Java putObject InvalidRedirectLocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48958754/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com