文档
测试
POST
teacher/resources/uploade

接口描述

上传资源

请求头

参数名
类型
描述
必填
token
必填

请求参数

参数名
类型
描述
必填
file
MultipartFile
图片,视频,文本
必填

响应参数

参数名
类型
描述
必填
code
必填
msg
必填
url
string
资源地址
必填

代码示例

/** * 上传照片 */ @PostMapping("/uploade") public R Upload(@RequestParam(value = "file") MultipartFile file) throws IOException { if (file.isEmpty()) { System.out.println("文件为空"); } String fileName = file.getOriginalFilename(); // 文件名 String suffixName = fileName.substring(fileName.lastIndexOf(".")); // 后缀名 String filePath = "D://temp-rainy//"; // 上传后的路径 fileName = UUID.randomUUID() + suffixName; // 新文件名 // Endpoint以杭州为例,其它Region请按实际情况填写。 String endpoint = "xxx"; String accessKeyId = "xxx"; String accessKeySecret = "xxx"; String bucketName = "xxx"; // <yourObjectName>表示删除OSS文件时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。 String objectName = "book/" + fileName; // 创建OSSClient实例。 OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(file.getBytes())); // 关闭OSSClient。 ossClient.shutdown(); return R.ok().put("url", objectName); }