中扬CRM客户关系管理系统
#
Junjie
2023-11-07 a421690c6c93f0f96d1db92026dfc18312c2b5c7
src/main/java/com/zy/crm/common/service/OssService.java
@@ -1,7 +1,6 @@
package com.zy.crm.common.service;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.OSSObject;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
@@ -12,20 +11,12 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import java.io.*;
import java.net.URL;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.nio.file.StandardCopyOption;
import java.nio.file.Files;
import java.nio.file.Paths;
/**
 * 阿里云OSS服务类
@@ -49,9 +40,6 @@
    private String bucket;
    @Value("${aliyun.oss.endpoint}")
    private String endpoint;
    @Value("${crmP.OSSENDPOINT}")
    private String OSS_ENDPOINT;
    @Autowired
@@ -195,20 +183,20 @@
    }
    public static void main(String[] args) {
        File file = new File("E:\\tmp\\v2-fbbb97b977b5cebc66dc3cefab0ac981_r.jpg");
        try {
            InputStream in = new FileInputStream(file);
            OssService ossService = new OssService();
            ossService.setAccessKeyId("LTAI4GDzr6ioSHuRw2mk22ug");
            ossService.setAccessKeySecret("84CHL7tF21LbU1qpaP0jn9mIAZP9bv");
            ossService.setBucket("tjdt");
            ossService.setEndpoint("http://oss-cn-hangzhou.aliyuncs.com");
            ossService.setSnowflakeIdWorker(new SnowflakeIdWorker());
            System.out.println(ossService.upload(in));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
//        File file = new File("E:\\tmp\\v2-fbbb97b977b5cebc66dc3cefab0ac981_r.jpg");
//        try {
//            InputStream in = new FileInputStream(file);
//            OssService ossService = new OssService();
//            ossService.setAccessKeyId("LTAI4GDzr6ioSHuRw2mk22ug");
//            ossService.setAccessKeySecret("84CHL7tF21LbU1qpaP0jn9mIAZP9bv");
//            ossService.setBucket("tjdt");
//            ossService.setEndpoint("http://oss-cn-hangzhou.aliyuncs.com");
//            ossService.setSnowflakeIdWorker(new SnowflakeIdWorker());
//            System.out.println(ossService.upload(in));
//
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        }
    }
}