Search code examples
javaspring-bootspring-mvclinode

How to Upload files and download files to LINODE object storage using Springboot?


I am using SpringBoot for development.

I need to upload and download files from Linode Object storage (similar to Amazon s3 bucket).

I didn't get any artifact dependency for development. I used Amazon S3 methods for development. But it ended up with an error saying Keys doesn't match s3.

Here is the config code:

@Configuration
public class WebSecurityConfig  {
    @Value("${cloud.linode.credentials.access-key}")
    private String accessKey;

    @Value("${cloud.linode.credentials.secret-key}")
    private String accessSecret;

    @Value("${cloud.linode.region.static}")
    private String region;

    @Bean
    public AmazonS3 linodeClient() {
        AWSCredentials credentials = new BasicAWSCredentials(accessKey, accessSecret);
        return AmazonS3ClientBuilder
                .standard()
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .withRegion(region)
                .build();
    }
}

How could I solve this? Need Linode methods.


Solution

  • You need to specify the Linode endpoint with withEndpointConfiguration

    @Bean
    public AmazonS3 linodeClient() {
        AWSCredentials credentials = new BasicAWSCredentials(accessKey, accessSecret);
        return AmazonS3ClientBuilder
                .standard()
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(
                        "https://" + region + ".linodeobjects.com", region))
                .withCredentials(new AWSStaticCredentialsProvider(credentials))
                .build();
    }