阿里云上传

复制代码
/**
 * 上传图片
 *
 * @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;
}

<!-- 阿里云oss依赖 -->

<dependency>

<groupId>com.aliyun.oss</groupId>

<artifactId>aliyun-sdk-oss</artifactId>

<version>3.4.2</version>

</dependency>

<!--好牛工具类-->

<dependency>

<groupId>com.github.hfhn</groupId>

<artifactId>hntool</artifactId>

<version>1.0.13</version>

</dependency>

main

复制代码
Vue.prototype.aliyunResource = function () {
  return "https://xxxxxx.oss-cn-hangzhou.aliyuncs.com/";
}
相关推荐
IT1995几秒前
C++使用“长度前缀法”解决TCP“粘包 / 拆包”问题
服务器·网络·c++·tcp/ip
wusp19941 分钟前
基于vite + nodejs + MongoDB + vue2 的博客发布系统
数据库·mongodb
全栈小51 分钟前
【数据库】浙人医携手金仓数据库,打造全国首个多院区异构多活容灾架构
数据库·1024程序员节·金仓
德迅云安全—珍珍2 分钟前
物理服务器、云服务器、裸金属服务器的区别
运维·服务器
好记忆不如烂笔头abc18 分钟前
超微服务器的ipmi调整风扇运行模式
运维·服务器
一个响当当的名号23 分钟前
ASP.NET 期末突击
运维·服务器
@Wufan30 分钟前
ubuntu服务器子用户(无sudo权限)安装/切换多个版本cuda
linux·服务器·ubuntu·cuda
studytosky32 分钟前
Linux 基础开发工具(3):Git 控制与 GDB 调试实用指南
linux·运维·服务器·网络·数据库·git
凌睿马37 分钟前
关于复杂数据结构从MySQL迁移到PostgreSQL的可行性
数据结构·数据库·mysql
吕了了38 分钟前
给U盘一个PE to Go:将微PE系统直接释放到U盘
运维·windows·电脑·系统