//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";
|
// }
|
//}
|