使用 aws-sdk-java 上传到 S3 存储桶时出现 PermanentRedirect 错误
PermanentRedirect error while uploading to S3 bucket with aws-sdk-java
我正在尝试将文件从 java class 上传到 aws S3。
我正在使用给定的确切代码 here
我唯一更改的部分是:
private static String bucketName = "s3-us-west-2.amazonaws.com/<my-bubket-name>";
private static String keyName = "*** Provide key ***";
private static String uploadFileName = "/home/...<localpath>.../test123";
我不确定要在 Provide Key 中添加什么。但即使我这样离开,我也会收到这样的错误:
Error Message: The bucket is in this region: null.Please use this region to retry the request (Service: Amazon S3; Status Code: 301; Error Code: PermanentRedirect; Request ID: *******)
HTTP Status Code: 301
AWS Error Code: PermanentRedirect
Error Type: Client
而不是 s3-us-west-2.amazonaws.com/<my-bucket-name>
你应该输入 <my-bucket-name>
.
您需要指定存储桶的名称。 KeyName 是指定存储桶中要存储文件的位置。它应该是这样的:
private static String bucketName = "xyz";// xyz is my bucket name at s3
private static String keyName = "upload/test/";// this is location where
//file will be stored
private static String uploadFileName = "/home/...<localpath>.../test123";
确保您使用了正确的区域。
将区域从 us-west-2
更改为 us-east-1
对我有用。
我正在尝试将文件从 java class 上传到 aws S3。
我正在使用给定的确切代码 here
我唯一更改的部分是:
private static String bucketName = "s3-us-west-2.amazonaws.com/<my-bubket-name>";
private static String keyName = "*** Provide key ***";
private static String uploadFileName = "/home/...<localpath>.../test123";
我不确定要在 Provide Key 中添加什么。但即使我这样离开,我也会收到这样的错误:
Error Message: The bucket is in this region: null.Please use this region to retry the request (Service: Amazon S3; Status Code: 301; Error Code: PermanentRedirect; Request ID: *******) HTTP Status Code: 301 AWS Error Code: PermanentRedirect Error Type: Client
而不是 s3-us-west-2.amazonaws.com/<my-bucket-name>
你应该输入 <my-bucket-name>
.
您需要指定存储桶的名称。 KeyName 是指定存储桶中要存储文件的位置。它应该是这样的:
private static String bucketName = "xyz";// xyz is my bucket name at s3
private static String keyName = "upload/test/";// this is location where
//file will be stored
private static String uploadFileName = "/home/...<localpath>.../test123";
确保您使用了正确的区域。
将区域从 us-west-2
更改为 us-east-1
对我有用。