简体   繁体   中英

How can we use OVH s3 api to access ovh cloud storage in java

I want to use ovh s3 api to access ovh cloud storage in java using keystore, secret key, consumer key and region. So using that i can upload files on ovh cloud storage.

Before using Java to connect to your backend I suggest you validate your connection with the CLI client like following

  • Get your tokens you will need to generated them as explained in this documentation: https://docs.ovh.com/gb/en/storage/getting_started_with_the_swift_S3_API/

    Important steps are:

    1. Source your openrc file
    user@host:~$ source <user_name>-openrc.sh
    1. create your ec2 credentials
      You will get a block with it as a response from this call
    user@host:~$ openstack ec2 credentials create
    1. edit your aws credentials
      be sure to provide the region and correct links to OVHcloud storage
    user@host:~$ cat ~/.aws/credentials [default] aws_access_key_id = <access_key> aws_secret_access_key = <secret_key> user@host:~$ cat ~/.aws/config [plugins] endpoint = awscli_plugin_endpoint [profile default] region = <region> s3 = endpoint_url = https://s3.<region>.cloud.ovh.net signature_version = s3v4 s3api = endpoint_url = https://s3.<region>.cloud.ovh.net
  • Validate the connectivity of your bucket by listing your OVHcloud storage objects.

     aws --profile default s3 ls

Then you can connect from java code you can use the code sample from this post answer Setting AWS S3 Region

AWSCredentials cred = new BasicAWSCredentials(<accessKey>,<secretKey>);
AmazonS3 s3client = AmazonS3ClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(cred))
.withClientConfiguration(<your configuration>)
.withRegion(Region.getRegion(Regions.AP_SOUTH_1));

Important thing is to provide the endpoint/region because sdk defaults to US_WEST region

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM