使用aws-sdk-java上传S3桶时,永久错误



我正在尝试从java类上传文件到aws S3。

我使用这里给出的确切代码

我只修改了这些部分:

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";

我不确定在提供密钥中添加什么。但即使我保持这种方式,我得到一个错误像这样:

Error Message: bucket is in this region: null。请使用此区域重试请求(服务:Amazon S3;状态码:301;错误代码:PermanentRedirect;请求ID: *******)HTTP状态码:301AWS错误代码:PermanentRedirect错误类型:Client

<my-bucket-name>代替s3-us-west-2.amazonaws.com/<my-bucket-name>

您需要指定bucket的名称。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对我有效。

相关内容

最新更新