英文:
Getting NoSuchMethoError While uploading file on Amazon S3 bucket
问题
以下是翻译好的部分:
我正在尝试使用无服务器架构将文件上传到Amazon S3存储桶,下面是描述的流程:
ApiGateway -> Lambda -> S3存储桶
我正在使用Postman发送请求,图像被编码为base64格式并在键"base64"中传递,然后将其转换为输入流并传递给putObject
方法,但在这一步出现了错误,错误消息显示为puObject
方法的NoSuchMethodError
,但实际是获取以下错误:
错误堆栈跟踪:
com.amazonaws.services.s3.model.AmazonS3Exception.setProxyHost(Ljava/lang/String;)V: java.lang.NoSuchMethodError
java.lang.NoSuchMethodError: com.amazonaws.services.s3.model.AmazonS3Exception.setProxyHost(Ljava/lang/String;)V
at com.amazonaws.services.s3.internal.AmazonS3ExceptionBuilder.build(AmazonS3ExceptionBuilder.java:266)
at com.amazonaws.services.s3.internal.S3ErrorResponseHandler.createException(S3ErrorResponseHandler.java:164)
...(以下堆栈跟踪略)
使用的方法:
public Object OperationHandler(MerchantSignUpRequest merchantSignUpRequest, Context context)
{
SignUpResponse signUpResponse=new SignUpResponse();
LOG.info(new Gson().toJson(merchantSignUpRequest));
AmazonS3 s3client = AmazonS3ClientBuilder.standard()
.withCredentials(DefaultAWSCredentialsProviderChain.getInstance())
.build();
String timeStamp = new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss").format(new java.util.Date());
String bucketName="nownowhub";String name="12345678.jpg";
InputStream is = new ByteArrayInputStream(merchantSignUpRequest.getBase64().getBytes());
s3client.putObject(new PutObjectRequest(bucketName,name,is,new ObjectMetadata()).withCannedAcl(
CannedAccessControlList.PublicRead));
S3Object s3Object=s3client.getObject(new GetObjectRequest(
bucketName,name));
return (s3Object.getObjectContent().getHttpRequest().getURI().toString());
}
catch (Exception e)
{
e.printStackTrace();
return "";
}
英文:
I was trying upload the file in Amazon s3 bucket using the server-less architecture below is the described flow
ApiGateway->lambda->s3bucket
I am sending Request using postman, image is encoded into the base64 format and passed in key"base64" then convert it into inputstream and passing in putObject
method but this where error is occurring it says
NoSuchMethodError
for puObject
method
but getting the below error
error stack trace:
com.amazonaws.services.s3.model.AmazonS3Exception.setProxyHost(Ljava/lang/String;)V:
java.lang.NoSuchMethodError
java.lang.NoSuchMethodError: com.amazonaws.services.s3.model.AmazonS3Exception.setProxyHost(Ljava/lang/String;)V
at com.amazonaws.services.s3.internal.AmazonS3ExceptionBuilder.build(AmazonS3ExceptionBuilder.java:266)
at com.amazonaws.services.s3.internal.S3ErrorResponseHandler.createException(S3ErrorResponseHandler.java:164)
at com.amazonaws.services.s3.internal.S3ErrorResponseHandler.handle(S3ErrorResponseHandler.java:71)
at com.amazonaws.services.s3.internal.S3ErrorResponseHandler.handle(S3ErrorResponseHandler.java:52)
at com.amazonaws.http.AwsErrorResponseHandler.handleAse(AwsErrorResponseHandler.java:53)
at com.amazonaws.http.AwsErrorResponseHandler.handle(AwsErrorResponseHandler.java:41)
at com.amazonaws.http.AwsErrorResponseHandler.handle(AwsErrorResponseHandler.java:26)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1781)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleServiceErrorResponse(AmazonHttpClient.java:1383)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1359)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1139)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:796)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:764)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:738)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:698)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:680)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:544)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:524)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:5219)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:5165)
at com.amazonaws.services.s3.AmazonS3Client.access$300(AmazonS3Client.java:405)
at
com.amazonaws.services.s3.AmazonS3Client$PutObjectStrategy.invokeServiceCall(AmazonS3Client.java:6180)
at com.amazonaws.services.s3.AmazonS3Client.uploadObject(AmazonS3Client.java:1824)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1784)
at com.nownow.aws.handler.MerchantOperationHandler.OperationHandler(MerchantOperationHandler.java:56)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
Used method:
public Object OperationHandler(MerchantSignUpRequest merchantSignUpRequest, Context context)
{ SignUpResponse signUpResponse=new SignUpResponse();
LOG.info(new Gson().toJson(merchantSignUpRequest));
AmazonS3 s3client = AmazonS3ClientBuilder.standard()
.withCredentials(DefaultAWSCredentialsProviderChain.getInstance())
.build();
String timeStamp = new SimpleDateFormat("yyyy-MM-dd.HH:mm:ss").format(new java.util.Date());
String bucketName="nownowhub";String name="12345678.jpg";
InputStream is = new ByteArrayInputStream(merchantSignUpRequest.getBase64().getBytes());
s3client.putObject(new PutObjectRequest(bucketName,name,is,new ObjectMetadata()).withCannedAcl(
CannedAccessControlList.PublicRead));
S3Object s3Object=s3client.getObject(new GetObjectRequest(
bucketName,name));
return (s3Object.getObjectContent().getHttpRequest().getURI().toString());
}catch (Exception e)
{
e.printStackTrace();
return "";
}
答案1
得分: 1
请确保您正在使用相同版本的 aws-java-sdk-core
和 aws-java-sdk-s3
,并且它们是最新版本。例如:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.883</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.883</version>
</dependency>
英文:
please make sure you are using same version aws-java-sdk-core
and aws-java-sdk-s3
and are of newest versions
for example:-
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-core</artifactId>
<version>1.11.883</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-s3 -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.883</version>
</dependency>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论