Commit 433f3c21 by 邓实川 Committed by chenzg

oss

parent 0ba0d2c4
...@@ -8,7 +8,6 @@ import org.apache.ibatis.annotations.Param; ...@@ -8,7 +8,6 @@ import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -105,20 +104,20 @@ public class OSSController { ...@@ -105,20 +104,20 @@ public class OSSController {
} }
} }
/** // /**
* 下载 // * 下载
*/ // */
@GetMapping(value = "/download") // @GetMapping(value = "/download")
@ApiOperation(value = "通过url直接下载文件", httpMethod = "GET", notes = "接口发布说明") // @ApiOperation(value = "通过url下载文件到服务器", httpMethod = "GET", notes = "接口发布说明")
public Result<String> download(@CurrentUser UserBean userBean, @RequestParam String url, // public Result<String> download(@CurrentUser UserBean userBean, @RequestParam String url,
@RequestParam String savePath) { // @RequestParam String savePath) {
try { // try {
oss.download(url, savePath); // oss.download(url, savePath);
} catch (Exception e) { // } catch (Exception e) {
return ResultUtil.error("下载失败"); // return ResultUtil.error("下载失败");
} // }
return ResultUtil.data("下载成功"); // return ResultUtil.data("下载成功");
} // }
/** /**
* 获取私密文件url(设置为10分钟有效) * 获取私密文件url(设置为10分钟有效)
......
...@@ -29,6 +29,7 @@ import com.aliyun.oss.model.ListObjectsRequest; ...@@ -29,6 +29,7 @@ import com.aliyun.oss.model.ListObjectsRequest;
import com.aliyun.oss.model.OSSObject; import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.OSSObjectSummary; import com.aliyun.oss.model.OSSObjectSummary;
import com.aliyun.oss.model.ObjectListing; import com.aliyun.oss.model.ObjectListing;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectRequest; import com.aliyun.oss.model.PutObjectRequest;
import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateField;
...@@ -496,11 +497,13 @@ public class OSSUtil { ...@@ -496,11 +497,13 @@ public class OSSUtil {
// String accessKeySecret = "EJ6qToT4T4u0B5Rb6qrta9WkyGHvGR"; // String accessKeySecret = "EJ6qToT4T4u0B5Rb6qrta9WkyGHvGR";
// String bucketName = "8time-v2"; // String bucketName = "8time-v2";
// String objectName = "8timer2.0/117/test/测试.pdf"; // String objectName = "8timer2.0/117/test/测试.pdf";
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
// String url = "http://8time-v2.oss-cn-shenzhen.aliyuncs.com/8timer2.0/310/qyxx/filepath/158872957193802f4a85a-9dd9-483a-9049-86fac5c73bd5.pdf?Expires=4747952308&OSSAccessKeyId=LTAI4FuaShJWQ1dggsFWG5CC&Signature=z%2FNIX0RrxnLuBLAS9olPpxxsCrI%3D"; // String url = "http://8time-v2.oss-cn-shenzhen.aliyuncs.com/8timer2.0/310/qyxx/filepath/158872957193802f4a85a-9dd9-483a-9049-86fac5c73bd5.pdf?Expires=4747952308&OSSAccessKeyId=LTAI4FuaShJWQ1dggsFWG5CC&Signature=z%2FNIX0RrxnLuBLAS9olPpxxsCrI%3D";
try { try {
// 带进度条的下载。 // 带进度条的下载。
ossClient.getObject(new GetObjectRequest(new URL(url), null), new File(savePath)); ObjectMetadata a = ossClient.getObject(new GetObjectRequest(new URL(url), null), new File(savePath));
System.err.println(a);
// new File("C:\\Users\\Lenovo\\Desktop\\8小时\\test2.pdf")); // new File("C:\\Users\\Lenovo\\Desktop\\8小时\\test2.pdf"));
// // 带进度条的下载。 // // 带进度条的下载。
// ossClient.getObject(new GetObjectRequest(bucketName, objectName).<GetObjectRequest>withProgressListener( // ossClient.getObject(new GetObjectRequest(bucketName, objectName).<GetObjectRequest>withProgressListener(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment