import com.aliyun.oss.*;
import com.aliyun.oss.model.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.locks.ReentrantLock;
/**
* This sample demonstrates how to upload multiparts to Aliyun OSS
* using the OSS SDK for Java.
*/
public class MultipartUpload {
private static final Logger logger = LoggerFactory.getLogger(MultipartUpload.class);
private static String endpoint = "**********";
private static String accessKeyId = "**********";
private static String accessKeySecret = "**********";
private static String bucketName = "**********";
private static String key = null;
private static String localFilePath = "**********";
private static OSS client = null;
// 定长线程池
private static ExecutorService threadPool;
private static List<PartETag> partETags = null;
private static final int partSize = 5 * 1024 * 1024; // 5MB 分片大小
private static String upload(String localPath) throws IOException {
long start = System.currentTimeMillis();
String[] names = localPath.split("\\.");
String fileTypeName = names[names.length - 1];
key = localFilePath + UUIDUtil.getUUID() + "." + fileTypeName;
ClientConfiguration conf = new ClientConfiguration();
conf.setIdleConnectionTime(5000);
client = new OSSClient(endpoint, accessKeyId, accessKeySecret, conf);
File sampleFile = null;
String fileUrl = null;
try {
String up
OSS 大文件分片上传
最新推荐文章于 2024-07-30 15:37:33 发布