aliyunmaven
*
阿里云公共仓库
C:\D\soft\Maven_Repo
com.aliyun.oss
aliyun-sdk-oss
2.8.3
joda-time
joda-time
2.10.1
aliyun.oss.file.endpoint=your endpoint
aliyun.oss.file.keyid=your accessKeyId
aliyun.oss.file.keysecret=your accessKeySecret
aliyun.oss.file.bucketname=your bucketname
@Component
public class ConstantPropertiesUtil implements InitializingBean {
@Value(“${aliyun.oss.file.endpoint}”)
private String endPoint;
@Override
public void afterPropertiesSet throws Exception {
ENDPOINT = endPoint;
// 其他配置初始化
@Data
public class R {
private Boolean success;
private Integer code;
private String message;
private Map data = new HashMap;
public static R ok {
R r = new R;
r.setSuccess(true);

r.setCode(ResultCode.SUCCESS);
r.setMessage(“操作成功”);
return r;
@RestController
public class FileUploadController {
@PostMapping(“/upload”)
public R uploadFile(@RequestParam(“file”) MultipartFile file) {
try {
// 创建OSSClient实例
OSS ossClient = new OSSClientBuilder.build(endpoint, accessKeyId, accessKeySecret);
// 上传文件流
InputStream inputStream = file.getInputStream;
ossClient.putObject(bucketName, fileName, inputStream);
// 关闭OSSClient
ossClient.shutdown;
return R.ok.data(“url”, “文件访问URL”);
} catch (Exception e) {
return R.error.message(“文件上传失败”);
内容均以整理官方公开资料,价格可能随活动调整,请以购买页面显示为准,如涉侵权,请联系客服处理。
本文由星速云发布。发布者:星速云。禁止采集与转载行为,违者必究。出处:https://www.67wa.com/15166.html