| | |
| | | |
| | | private static Logger log = LoggerFactory.getLogger(OssService.class); |
| | | |
| | | // private static final String OSS_ENDPOINT = "http://oss-cn-hangzhou-internal.aliyuncs.com"; |
| | | |
| | | @Value("${aliyun.oss.id}") |
| | | private String accessKeyId; |
| | | |
| | |
| | | |
| | | @Value("${aliyun.oss.endpoint}") |
| | | private String OSS_ENDPOINT; |
| | | |
| | | @Value("${aliyun.oss.endpoint2}") |
| | | private String OSS_ENDPOINT2; |
| | | |
| | | @Autowired |
| | | private SnowflakeIdWorker snowflakeIdWorker; |
| | |
| | | // .body(resource); |
| | | // } |
| | | |
| | | public static ByteArrayInputStream convertToByteArrayInputStream(InputStream inputStream) throws IOException { |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| | | byte[] buffer = new byte[4096]; |
| | | int bytesRead; |
| | | while ((bytesRead = inputStream.read(buffer)) != -1) { |
| | | outputStream.write(buffer, 0, bytesRead); |
| | | } |
| | | byte[] data = outputStream.toByteArray(); |
| | | return new ByteArrayInputStream(data); |
| | | } |
| | | |
| | | @Deprecated |
| | | public String download(String name) { |
| | | OSSClient ossClient = new OSSClient(OSS_ENDPOINT, accessKeyId, accessKeySecret); |
| | | OSSClient ossClient = new OSSClient(OSS_ENDPOINT2, accessKeyId, accessKeySecret); |
| | | //获取临时下载链接 |
| | | URL url = ossClient.generatePresignedUrl(bucket, name, new Date(new Date().getTime() + 3600 * 1000)); |
| | | log.info("OSS文件临时下载路径,URL路径: {}", url); |