All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.branch.cos.demo.CAMRoleDemo Maven / Gradle / Ivy

There is a newer version: 5.6.20
Show newest version
package com.branch.cos.demo;

import com.branch.cos.COSClient;
import com.branch.cos.ClientConfig;
import com.branch.cos.auth.*;
import com.branch.cos.model.PutObjectRequest;
import com.branch.cos.model.PutObjectResult;
import com.branch.cos.model.StorageClass;
import com.branch.cos.region.Region;

import java.io.File;

public class CAMRoleDemo {

    public static void SimpleUploadFileFromLocal() {
        InstanceMetadataCredentialsEndpointProvider endpointProvider =
                new InstanceMetadataCredentialsEndpointProvider(InstanceMetadataCredentialsEndpointProvider.Instance.CVM);

        InstanceCredentialsFetcher instanceCredentialsFetcher = new InstanceCredentialsFetcher(endpointProvider);
        COSCredentialsProvider cosCredentialsProvider = new InstanceCredentialsProvider(instanceCredentialsFetcher);
        ClientConfig clientConfig = new ClientConfig(new Region("ap-guangzhou"));
        COSClient cosClient = new COSClient(cosCredentialsProvider,clientConfig);
        String bucketName = "3399demo-125xxxxxxxx";
        String key = "test/demo.txt";
        File localFile = new File("test");
        PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, localFile);
        putObjectRequest.setStorageClass(StorageClass.Standard);
        PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest);
        cosClient.shutdown();
    }

    public static void main(String[] args) {
        SimpleUploadFileFromLocal();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy