阿里云上传

复制代码
/**
 * 上传图片
 *
 * @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/";
}
相关推荐
祁鱼鱼鱼鱼鱼3 分钟前
Location 字符匹配详解
linux·服务器·前端
祁鱼鱼鱼鱼鱼6 分钟前
Nginx反向代理及反向代理负载均衡
linux·服务器·前端
雪的季节7 分钟前
qt中destroyed
数据库
数据知道7 分钟前
claw-code 源码分析:Turn Loop 里的工程细节——多轮对话如何在移植期保持可测试、可回放?
服务器·数据库·ai·claude code
J2虾虾11 分钟前
Linux 定时备份 MySQL 数据库(完整教程)
linux·运维·数据库
爱学习的程序媛15 分钟前
Docker常用指令速查手册
运维·docker·容器
Hawk Yang15 分钟前
从零开始:Windows 连接 Linux 服务器的 SSH 免密登录教程
linux·服务器·windows
数据知道17 分钟前
claw-code 源码分析:Transcript / Session Store——智能体「运行史」数据结构怎样才算可运维?
运维·数据结构·python·ai·claude code
一 乐18 分钟前
鲜花商城|基于springboot + vue鲜花商城系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·论文·毕设·鲜花商城系统