阅读背景:

阿里云对象存储-图片存储

来源:互联网 
1.依赖jar <!--阿里云对象存储--> <dependency> <groupId>com.aliyun.oss</groupId> <artifactId>aliyun-sdk-oss</artifactId> <version>2.8.3</version> </dependency> 2.实例 @PatchMapping("/pic/alimg") @ApiOperation(value = "阿里图片上传") @ResponseBody public String picOSS(MultipartFile uploadFile) throws Exception { String endpoint = "https://oss-cn-shanghai.aliyuncs.com"; // 云账号AccessKey有所有API访问权限,建议遵循阿里云安全最佳实践,创建并使用RAM子账号进行API访问或日常运维,请登录 // https://ram.console.aliyun.com 创建 String accessKeyId = ""; String accessKeySecret = ""; // 创建OSSClient实例 OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret); // 上传 String filename = FtpUtil.genImageName() + uploadFile.getOriginalFilename().substring(uploadFile.getOriginalFilename().lastIndexOf(".")); ossClient.putObject(bucktName, filename, new ByteArrayInputStream(uploadFile.getBytes())); // 关闭client ossClient.shutdown(); Date expiration = new Date(new Date().getTime() + 3600l * 1000 * 24 * 365 * 10); String url = ossClient.generatePresignedUrl(bucktName, filename, expiration).toString(); System.out.println(url); return url; } 3.结果 1.依赖jar <!--阿里云对象存储--> <dependency> <groupI



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: