阿里云上传

/**
 * 上传图片
 *
 * @param file 文件
 * @return
 * @throws Exception
 */
@PostMapping(value = "/aliUpload")
@ResponseBody
public AjaxResult aliUpload(MultipartFile file){
    //获取文件后缀
    String extension = FileUploadUtils.getExtension(file);
    String imgFormat = "{}/{}/{}.{}";
    String currentDate = DateUtil.format(DateUtil.date(), "yyyy/MM/dd");
    AjaxResult ajaxResult = AjaxResult.success();
    String fileName = FileUploadUtil.uploadFile(UploadPlatform.Ali, file,
            StrUtil.format(imgFormat, "img", currentDate, RandomUtil.randomString(16),extension));
    String urlFormat = "{}/{}";
    String url = StrUtil.format(urlFormat, "img", fileName);
    ajaxResult.put("url", url);
    ajaxResult.put("fileName", fileName);
    return ajaxResult;
}



com.aliyun.oss
aliyun-sdk-oss
3.4.2



com.github.hfhn
hntool
1.0.13
 

阿里云上传_第1张图片 

main

Vue.prototype.aliyunResource = function () {
  return "https://xxxxxx.oss-cn-hangzhou.aliyuncs.com/";
}

 

你可能感兴趣的:(数据库,服务器,运维)