阿里云上传

复制代码
/**
 * 上传图片
 *
 * @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/";
}
相关推荐
青衫码上行18 小时前
Redis的事务操作
数据库·redis
叠叠乐18 小时前
EasyTier 免费自建自用5$每个月的服务器
linux·运维·bash
草莓熊Lotso18 小时前
Qt 核心事件系统全攻略:鼠标 / 键盘 / 定时器 / 窗口 + 事件分发与过滤
运维·开发语言·c++·人工智能·qt·ui·计算机外设
堕27418 小时前
MySQL数据库《基础篇--库的操作和数据类型》
数据库·mysql
Web极客码18 小时前
解决WordPress迁移后重定向到旧域名的问题
数据库·wordpress·网站迁移
Web打印20 小时前
Phpask(php集成环境)之15 phpstudy转移到phpask
数据库·mysql
LaughingZhu1 天前
Product Hunt 每日热榜 | 2026-02-14
数据库·人工智能·经验分享·神经网络·搜索引擎·chatgpt
DeeplyMind1 天前
第12章 Docker存储机制(重要)
运维·docker·容器
软件派1 天前
近两年国外主流数据库深度解析:从技术特性到场景适配
数据库
Elastic 中国社区官方博客1 天前
DevRel 通讯 — 2026 年 2 月
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·jina