Skip to content
Advertisement

Getting NoSuchMethoError While uploading file on Amazon S3 bucket

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

Advertisement

Answer

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>
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement