com.aliyun.uploader.BaseOssUploader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toolkit-maven-plugin Show documentation
Show all versions of toolkit-maven-plugin Show documentation
Aliyun Open API SDK for Java
Copyright (C) Alibaba Cloud Computing
All rights reserved.
版权所有 (C)阿里云计算有限公司
http://www.aliyun.com
package com.aliyun.uploader;
import com.aliyun.CommonUtils;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.PutObjectRequest;
import java.io.File;
import java.io.FileInputStream;
import java.net.URLEncoder;
public abstract class BaseOssUploader implements Uploader {
private static final String OSS_ENDPOINT_PTN = "http://oss-%s.aliyuncs.com";
private static final String OSS_DOWNLOAD_URL_PTN = "https://%s.oss-%s-internal.aliyuncs.com/%s";
protected String doUpload(String regionId, String bucket, String key, File file, String ak, String sk, String token)
throws Exception {
String endpoint = String.format(OSS_ENDPOINT_PTN, regionId);
OSSClient ossClient = CommonUtils.isEmpty(token) ? new OSSClient(endpoint, ak, sk) : new OSSClient(endpoint, ak,
sk, token);
ossClient.putObject(new PutObjectRequest(bucket, key, new FileInputStream(file))
.withProgressListener(new OssUploadProgressListener(file.length())));
ossClient.shutdown();
return String.format(OSS_DOWNLOAD_URL_PTN, bucket, regionId,
URLEncoder.encode(key, "UTF-8").replaceAll("%2F", "/"));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy