gpt4 book ai didi

java - 使用java上传文件到S3

转载 作者:行者123 更新时间:2023-12-01 11:00:47 25 4
gpt4 key购买 nike

我想使用 maven java 项目将文件上传到 S3 存储桶。

void uploadFile(String filePath,String fileName) throws IOException{
String bucketName="my-feeds/prod/myfiles/myData";
String currentDir = System.getProperty("user.dir");
input = new FileInputStream(currentDir+"/src/main/resources/keyDetails.properties");
prop.load(input);
String YourAccessKeyID = prop.getProperty("accessKey");
String YourSecretAccessKey = prop.getProperty("secretKey");
AWSCredentials credentials = new BasicAWSCredentials(YourAccessKeyID, YourSecretAccessKey);
AmazonS3 s3client = new AmazonS3Client(credentials);
s3client.putObject(bucketName, fileName, new File(filePath));
}

但是我遇到了异常:

Exception in thread "main" java.lang.NoSuchMethodError: com.amazonaws.AmazonWebServiceRequest.copyPrivateRequestParameters()Ljava/util/Map;

原因是什么?请帮忙。

我的 pom.xml 将此作为依赖项:

<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.9.0</version>
</dependency>

现在得到这个异常

Exception in thread "main" com.amazonaws.services.s3.model.AmazonS3Exception: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. (Service: Amazon S3; Status Code: 301; Error Code: PermanentRedirect; " 

更新版本后

最佳答案

存储桶名称应该只是my-feedsprod/myfiles/myData 部分是 key 的一部分,而不是存储桶的一部分。

关于java - 使用java上传文件到S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33348318/

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