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

com.aliyun.uploader.UserOssUploader Maven / Gradle / Ivy

Go to download

Aliyun Open API SDK for Java Copyright (C) Alibaba Cloud Computing All rights reserved. 版权所有 (C)阿里云计算有限公司 http://www.aliyun.com

There is a newer version: 1.1.9
Show newest version
package com.aliyun.uploader;

import com.aliyun.CommonUtils;
import com.aliyun.bean.DefaultConfigBean;

import java.io.File;

public class UserOssUploader extends BaseOssUploader {
    private static final String NAME = "User OSS Uploader";

    private String regionId;
    private String bucket;
    private String key;
    private String ak;
    private String sk;
    private DefaultConfigBean config;

    private String generateKey() {
        String ptn = CommonUtils.isEmpty(this.key) ? "{region_id}/{app_id}/{version}" : this.key;
        return ptn.replaceAll("\\{region_id}", config.getEnv().getRegionId())
            .replaceAll("\\{app_id}", config.getApp().getAppId())
            .replaceAll("\\{version}", config.getApp().getPackageVersion());
    }

    UserOssUploader(String regionId, String bucket, String key, String ak, String sk, DefaultConfigBean config) {
        this.regionId = regionId;
        this.bucket = bucket;
        this.key = key;
        this.ak = ak;
        this.sk = sk;
        this.config = config;
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public String upload(File file) throws Exception {
        return doUpload(this.regionId, this.bucket, generateKey(), file, this.ak, this.sk, null);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy