Java实现腾讯云COS高级(大文件)上传,不考虑分块

	// 腾讯云COS高级(大文件)上传,不用考虑分块
	public static URL fileCOS(File file, String key) throws Exception {
		String SecretKey = "SecretKey";
		String SecretId = "SecretId";
		COSCredentials cred = new BasicCOSCredentials(SecretKey, SecretId);
		// 2 设置bucket的区域, COS地域的简称请参照
		// https://cloud.tencent.com/document/product/436/6224
		ClientConfig clientConfig = new ClientConfig(new Region("bucket的区域"));
		// 3 生成cos客户端
		COSClient cosClient = new COSClient(cred, clientConfig);
		// bucket的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式
		String bucketName = {name}-{appid};
		
		//创建线程池
		ExecutorService threadPool = Executors.newFixedThreadPool(32);
		// 传入一个 threadpool, 若不传入线程池, 默认 TransferManager 中会生成一个单线程的线程池。
		TransferManager transferManager = new TransferManager(cosClient, threadPool);
		//分装与上传
		PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, file);
		Upload upload = transferManager.upload(putObjectRequest);
		 // 等待传输结束(如果想同步的等待上传结束,则调用 waitForCompletion)
		upload.waitForUploadResult();
		// 关闭 TransferManger
		transferManager.shutdownNow();
		Date expiration = new Date(new Date().getTime() + 5 * 60 * 10000);
		URL url = cosClient.generatePresignedUrl(bucketName, key, expiration);
		return url;
	} 

本文是对上篇(腾讯云 对象储存java实现COS文件上传与返回的URL)补充

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bug修得完

更多技术知识可关注询问,谢谢!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值