[英]Unable to download a jar file from AmazonS3
I'm trying to download a jar file from S3 using the approach of this accepted answer: 我正在尝试使用以下已接受答案的方法从S3下载jar文件:
https://stackoverflow.com/a/32822091/6532976 https://stackoverflow.com/a/32822091/6532976
But I'm getting this error: 但我收到此错误:
Error:(61, 36) java: constructor GetObjectRequest in class com.amazonaws.services.mediastoredata.model.GetObjectRequest cannot be applied to given types; required: no arguments found: java.lang.String,java.lang.String reason: actual and formal argument lists differ in length
I understand that GetObjectRequest doesn't require any arguments but I've found some online examples on how to use GetObjectRequest such as this: https://www.programcreek.com/java-api-examples/?api=com.amazonaws.services.s3.model.GetObjectRequest which clearly passed parameters to GetObjectRequest. 我了解GetObjectRequest不需要任何参数,但是我发现了一些有关如何使用GetObjectRequest的在线示例,例如: https ://www.programcreek.com/java-api-examples/?api =com.amazonaws。 services.s3.model.GetObjectRequest将参数明确传递给GetObjectRequest。
So, which is the correct procedure to download a JAR file from S3? 那么,从S3下载JAR文件的正确过程是什么?
Edit: My code which is causing the error 编辑:我的代码导致错误
AWSCredentials myCredentials = new BasicAWSCredentials(access_key, secret_key);
AmazonS3Client s3Client;
s3Client = new AmazonS3Client(myCredentials);
GetObjectRequest request = new GetObjectRequest(bucketname, jarFilePathInBucket);
S3Object object = s3Client.getObject(request);
S3ObjectInputStream objectContent = object.getObjectContent();
FileOutputStream fos = new FileOutputStream(pathToJarFile);
byte[] buffer = new byte[4096];
int buf = 0;
while((buf = objectContent.read(buffer)) > 0)
{
fos.write(buffer, 0, buf);
}
fos.close();
You haven't yet posted your code, but there really isn't an alternative for this. 您尚未发布代码,但实际上没有其他选择。
The AWS3 Java client libraries contain 2 classes named GetObjectRequest
. AWS3 Java客户端库包含2个名为
GetObjectRequest
类。 When you import
the class, you need to ensure that you take the right one. import
课程时,您需要确保选择正确的课程。
com.amazonaws.services.mediastoredata.model.GetObjectRequest
com.amazonaws.services.s3.model.GetObjectRequest
<-- this is the correct one com.amazonaws.services.s3.model.GetObjectRequest
<-这是正确的 The other class that's also called GetObjectRequest takes no constructor arguments. 另一个也称为GetObjectRequest的类不包含构造函数参数。 The one that you need has multiple overloaded constructors, including one overload that takes 2 Strings.
您需要一个具有多个重载的构造函数,其中一个重载需要2个String。
At the top of your file, you'll need to have a line that says 在文件顶部,您需要有一行文字
import com.amazonaws.services.s3.model.GetObjectRequest
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.