|
|
@@ -2,6 +2,7 @@ package com.izouma.awesomeadmin.web;
|
|
|
|
|
|
import com.izouma.awesomeadmin.dto.Result;
|
|
|
import com.izouma.awesomeadmin.service.OSSFileService;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
@@ -17,6 +18,7 @@ import java.io.IOException;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* Created by xiongzhu on 2017/3/8.
|
|
|
@@ -58,7 +60,9 @@ public class AssetsController {
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
randomCode.append(Integer.toString(random.nextInt(36), 36));
|
|
|
}
|
|
|
- String uploadPath = String.format("images/%s-%s.jpg", new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date()), randomCode);
|
|
|
+ String ext = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
|
|
+ String fileType = file.getContentType().substring(0, file.getContentType().indexOf("/"));
|
|
|
+ String uploadPath = String.format("%s/%s-%s%s", fileType, new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss").format(new Date()), randomCode, ext);
|
|
|
String path = OSSFileService.upload(file.getInputStream(), uploadPath);
|
|
|
paths.add(path);
|
|
|
} catch (IOException e) {
|