import com.qcloud.vod.VodUploadClient;
import com.qcloud.vod.model.VodUploadRequest;
import com.qcloud.vod.model.VodUploadResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Main {
public static void main(String[] args) throws Exception {
// 并发数
Integer threadNumber = 20;
// 待上传的文件路径列表
List<String> filePathList = new ArrayList<String>();
// 添加待上传文件路径
filePathList.add("/data/path1.mp4");
filePathList.add("/data/path2.mp4");
filePathList.add("/data/path3.mp4");
// 创建线程池
ExecutorService pool = Executors.newFixedThreadPool(threadNumber);
// 创建上传Client
VodUploadClient client = new VodUploadClient("your secretId", "your secretKey");
// 并发上传
for (String path : filePathList) {
// 提交上传任务
pool.submit(new UploadThread(client, path));
}
}
}
// 上传线程
class UploadThread implements Runnable {
// 上传 Client
private VodUploadClient uploadClient;
// 文件路径
private String filePath;
public UploadThread(VodUploadClient uploadClient, String filePath) {
this.uploadClient = uploadClient;
this.filePath = filePath;
}
public void run() {
VodUploadRequest request = new VodUploadRequest();
request.setMediaFilePath(filePath);
try {
// 执行上传
VodUploadResponse response = uploadClient.upload("ap-guangzhou", request);
System.out.println(response.getFileId());
} catch (Exception e) {
e.printStackTrace();
}
}
}
本页内容是否解决了您的问题?