关于springboot 腾讯云对象存储使用
因为老板从七牛云将图片存储转移到腾讯云,不得不重新写图片上传的接口。
先在pom中导入依赖。因为有个冲突,所以我去除了冲突的slf4j-log4j12包,整体项目运行没有影响
com.qcloud
cos_api
org.slf4j
slf4j-log4j12
5.4.10
关于腾讯云的图片上传,其实和大部分对象存储过程差不多,首先就是先从前端接收到图片。
@RequestMapping(value = "/fileUploadInTencent",method = RequestMethod.POST)
@ResponseBody
public String uploadFileInTencent(@RequestParam("file") MultipartFile file, HttpServletResponse response, HttpServletRequest request) throws ServletException, IOException {
JSONObject jo = new JSONObject();
if (file==null||"".equals(file)){
jo.put("msg","文件为空");
}else {
Map<String, String> urlMap = uploadService.uploadFileInTencent(file);
jo.put("url", urlMap.get("url"));
jo.put("key", urlMap.get("key"));
}
return jo.toString();
//abcaaa
//测试git提交
}
uploadService是实现建好