Skip to the content.

Tencent-Cloud-Object-Storage

README English | 简体中文

Introductions

Tencent-Cloud-Object-Storage is implementation of Storage project interfaces, based on Tencent Cloud Object Storage(COS) Service. It provides convenient data storage services for Spring Boot projects, including generate get, put, and remove urls to provide client access to avoid local IO.

Build Status GitHub GitHub release (latest by date) Sonatype Nexus (Releases) Sonatype Nexus (Snapshots)

Download

Grab via Maven:

<dependency>
  <groupId>cn.dustlight.storage</groupId>
    <artifactId>tencent-cloud-object-storage</artifactId>
  <version>0.0.6</version>
</dependency>

Configurations

application.yaml:

dustlight:
  storage:
    tencent:
      cos:
        secret-id: <SECRET_ID>
        secret-key: <SECRET_KEY>
        bucket: <BUCKET>
        region: <REGION>
#        general-api: 
#        service-api: service.cos.myqcloud.com
#        http-protocol: https

Or

application.properties:

dustlight.storage.tencent.cos.secret-id=<SECRET_ID>
dustlight.storage.tencent.cos.secret-key=<SECRET_KEY>
dustlight.storage.tencent.cos.bucket=<BUCKET>
dustlight.storage.tencent.cos.region=<REGION>
#dustlight.storage.tencent.cos.general-api=
#dustlight.storage.tencent.cos.service-api=service.cos.myqcloud.com
#dustlight.storage.tencent.cos.http-protocol=https

Configuration item interpretation:

Use

Simple use cases with TencentCloudObjectStorage look like this:

package com.example.demo;

import cn.dustlight.storage.core.Permission;
import cn.dustlight.storage.core.StorableObject;
import cn.dustlight.storage.local.LocalStorableObject;
import cn.dustlight.storage.local.LocalStorage;
import cn.dustlight.storage.tencent.cos.TencentCloudObjectStorage;
import cn.dustlight.storage.tencent.cos.TencentCloudStorableObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;

@SpringBootApplication
@Component
public class DemoApplication implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Autowired
    TencentCloudObjectStorage cloudStorage; // Tencent Cloud Storage
    LocalStorage localStorage = LocalStorage.defaultInstance; // Local Storage, the root path of defaultInstance is './'

    public void run(ApplicationArguments args) throws Exception {
        StorableObject test = localStorage.get("test.txt"); // Get the local object

        TencentCloudStorableObject test2 = cloudStorage.put("test.txt", test); // Copy to cloud storage

        String url = cloudStorage.generateGetUrl(test2.getKey(), 1000L * 60 * 5); // Generate a URL expired at 5 min later

        System.out.println(url);

        LocalStorableObject download = localStorage.put("download.txt", test2, Permission.PUBLIC); // Download from cloud storage to local storage

        System.out.println(download.getFile());
    }
}

See the wiki for full instructions.

Get Help

To report a specific problem or feature request, open a new issue on Github. For questions, suggestions, or anything else, email hansin@dustlight.cn.