OSS 大文件分片上传

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
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值