liujie
10 天以前 c196e41a7c9f2bd845d189486069c416eca9c968
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//package com.ruoyi.common.utils.file;
//
//import com.aliyun.oss.OSSClient;
//import com.aliyun.oss.model.ObjectMetadata;
//import org.springframework.web.multipart.MultipartFile;
////
//import javax.servlet.http.HttpServletRequest;
//import java.io.IOException;
//import java.io.InputStream;
//import java.util.UUID;
//
//public class OssUploadUtil {
//    public static String oss_domain = "https://yizhengcheng.oss-cn-chengdu.aliyuncs.com/";
//    public static String accessKeyId = "LTAI5tHYSpwifc3rqLYJoETo";
//    public static String accessKeySecret = "xrDyQ89h8P0alWW7rrLIW2D2rt7Eig";
//    public static String bucketName="yizhengcheng";
//    public static String endpoint = "oss-cn-chengdu.aliyuncs.com";
//
//
//    public static String ossUpload(HttpServletRequest request, MultipartFile file) throws IOException {
//        //CommonsMultipartFile file = (CommonsMultipartFile)multipartFile;
//        OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
//
//        String fileName = "";
//        if (file != null && !"".equals(file.getOriginalFilename()) && file.getOriginalFilename() != null) {
//            InputStream content = file.getInputStream();//获得指定文件的输入流
//            ObjectMetadata meta = new ObjectMetadata();// 创建上传Object的Metadata
//            meta.setContentLength(file.getSize());  // 必须设置ContentLength
//            String originalFilename = file.getOriginalFilename();
//            fileName = UUID.randomUUID().toString().replaceAll("-", "") + originalFilename.subSequence(originalFilename.lastIndexOf("."), originalFilename.length());
//            ossClient.putObject(bucketName, "img/" + fileName, content, meta);// 上传Object.
//            if (fileName != null && !"".equals(fileName)) {
//                fileName = oss_domain + "img/" + fileName;
//            }
//        }
//        return fileName;
//    }
//
//
//
//    //上传图片
//
//    /**
//     * 通过文件名判断并获取OSS服务文件上传时文件的contentType
//     *
//     * @param fileName
//     *            文件名
//     * @return 文件的contentType
//     */
//    public static String getContentType(String fileName) {
//        // 文件的后缀名
//        String fileExtension = fileName.substring(fileName.lastIndexOf("."));
//        if (".bmp".equalsIgnoreCase(fileExtension)) {
//            return "image/bmp";
//        }
//        if (".gif".equalsIgnoreCase(fileExtension)) {
//            return "image/gif";
//        }
//        if (".jpeg".equalsIgnoreCase(fileExtension) || ".jpg".equalsIgnoreCase(fileExtension)
//                || ".png".equalsIgnoreCase(fileExtension)) {
//            return "image/jpeg";
//        }
//        if (".html".equalsIgnoreCase(fileExtension)) {
//            return "text/html";
//        }
//        if (".txt".equalsIgnoreCase(fileExtension)) {
//            return "text/plain";
//        }
//        if (".vsd".equalsIgnoreCase(fileExtension)) {
//            return "application/vnd.visio";
//        }
//        if (".ppt".equalsIgnoreCase(fileExtension) || "pptx".equalsIgnoreCase(fileExtension)) {
//            return "application/vnd.ms-powerpoint";
//        }
//        if (".doc".equalsIgnoreCase(fileExtension) || "docx".equalsIgnoreCase(fileExtension)) {
//            return "application/msword";
//        }
//        if (".xml".equalsIgnoreCase(fileExtension)) {
//            return "text/xml";
//        }
//        if (".mp4".equalsIgnoreCase(fileExtension)) {
//            return "video/mp4";
//        }
//        // 默认返回类型
//        return "image/jpeg";
//    }
//}