上传图片
官网上找到的是上传绝对路径的代码,其实我们上传时是上传MultipartFile
类型
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key,inputStream,null);
这行代码在官网看是两个参数,写的是绝对路径,我们上传时需要给MultipartFile
类型转为InputStream
流类型,我们可以点开PutObjectRequest
会发现,他有重载方法传的是InputStream
流类型,不要被官网骗了
public String uploadImgVuserInfo(MultipartFile file) {
String path="https://9uc-1253537498.cos.ap-shanghai.myqcloud.com/";
COSCredentials cred = new BasicCOSCredentials("AKIDrpWw6zTz5uXtzKwEn56phJeiaAT3AQCj", "PdldIh2JK6bCXcU7i4F9mAI9mbCXbPHt");
// 2 设置bucket的区域, COS地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
// clientConfig中包含了设置region, https(默认http), 超时, 代理等set方法, 使用可参见源码或者接口文档FAQ中说明
ClientConfig clientConfig = new ClientConfig(new Region("ap-shanghai"));