无关风月
2024-12-25 72fcf54396940ac8d93609476f3a1fdd00521224
文件上传
2个文件已修改
67 ■■■■■ 已修改文件
common/src/main/java/com/jilongda/common/component/AliOss.java 23 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/src/main/java/com/jilongda/common/component/AliOssFileUploadController.java 44 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/src/main/java/com/jilongda/common/component/AliOss.java
@@ -10,35 +10,24 @@
    /**
     * 请填写您的AccessKeyId。LTAI5tPbJsVfBZZTPqPe8A2r
     */
    public static final String accessKeyId = "LTAI5tQZzqsZYX5gw8yRNchQ";
//    public static final String accessKeyId = "LTAI5tPbJsVfBZZTPqPe8A2r";
    public static final String accessKeyId = "LTAI5tL1dE1DzT4ZYdDQZ8k7";
    /**
     * 请填写您的AccessKeySecret。
     */
    public static final String accessKeySecret = "5yJVdXwRzwPZwKKXp07lRAc7tkTxQp";
//    public static final String accessKeySecret = "BvRc85RcX0bgrl9TMUOGHEMLUPlCr2";
    public static final String accessKeySecret = "4SZBtTyLhOoYRcfMS4SVAtGz8ZnxRP";
    /**
     * 请填写您的 endpoint。
     */
    public static final String endpoint = "oss-cn-hongkong.aliyuncs.com";
    public static final String endpoint = "oss-cn-shenzhen.aliyuncs.com";
    /**
     * 请填写您的 bucketname 。
     */
//    public static final String bucketName = "sales-bucket";
    public static final String bucketName = "bizuphk";
    /**
     * cdn
     */
//    public static final String cdn = "https://cdn.pharmacylinked.com";
//    public static final String cdn = "https://nncdn.pharmacylinked.com";
    public static final String bucketName = "yandu66";
    /**
     * host的格式为 bucketname.endpoint
     */
    public static final String host = "https://" + bucketName + "." + endpoint;
    public static final String host = "https://" + "yandu66.oss-cn-shenzhen.aliyuncs.com";
    //     此处不需要回调
//     callbackUrl为上传回调服务器的URL,请将下面的IP和Port配置为您自己的真实信息。
    public static final String callbackUrl = "https://alwaystest.xisheninfo.com/api/ali-oss/callback";
    public static String dir = "hollywood/";
    public static String dir = "eyes/";
}
common/src/main/java/com/jilongda/common/component/AliOssFileUploadController.java
@@ -41,28 +41,28 @@
    private String FILE_CDN;
    @ApiOperation(value = "单文件上传", notes = "单文件上传,rename 默认不重命名")
    @PostMapping(value = "strUpload", headers = "content-type=multipart/form-data")
    public String strUploads(@RequestParam(value = "file") MultipartFile mf) throws IOException {
        if (mf.isEmpty()) {
            return "请传入文件!";
        }
        String fileName = mf.getOriginalFilename();
        String TimeDir =new SimpleDateFormat("yyyy-MM-dd").format(new Date());
//        String realPath = "D:\\" + TimeDir;
        String realPath = "/usr/local/nginx/html/images/" + TimeDir;
        File file = new File(realPath);
        // 没有目录就创建
        if (!file.exists()) {
            file.mkdirs();
        }
        File targetFile = new File(realPath, fileName);//目标文件
        //开始从源文件拷贝到目标文件
        //传图片一步到位
        mf.transferTo(targetFile);
        //拼接数据
        return "http://eyes.chelota.com/images/" + TimeDir +"/"+ fileName;
    }
//    @ApiOperation(value = "单文件上传", notes = "单文件上传,rename 默认不重命名")
//    @PostMapping(value = "strUpload", headers = "content-type=multipart/form-data")
//    public String strUploads(@RequestParam(value = "file") MultipartFile mf) throws IOException {
//        if (mf.isEmpty()) {
//            return "请传入文件!";
//        }
//        String fileName = mf.getOriginalFilename();
//        String TimeDir =new SimpleDateFormat("yyyy-MM-dd").format(new Date());
////        String realPath = "D:\\" + TimeDir;
//        String realPath = "/usr/local/nginx/html/images/" + TimeDir;
//        File file = new File(realPath);
//        // 没有目录就创建
//        if (!file.exists()) {
//            file.mkdirs();
//        }
//        File targetFile = new File(realPath, fileName);//目标文件
//        //开始从源文件拷贝到目标文件
//        //传图片一步到位
//        mf.transferTo(targetFile);
//        //拼接数据
//        return "http://eyes.chelota.com/images/" + TimeDir +"/"+ fileName;
//    }
    @ApiOperation(value = "服务端上传", notes = "服务端上传")
    @PostMapping(value = "upload")
    public ApiResult<String> fileUpload(@RequestParam(value = "file") MultipartFile file) throws IOException {