Commit 502764fb authored by xiujunlian's avatar xiujunlian

上传图片重命名

parent c0739901
......@@ -11,6 +11,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -220,17 +221,27 @@ public class JgSubjectController extends AbstractController {
//String url = request.getSession().getServletContext().getRealPath("doc/");
String url ="C:/document/doc";
String newFileName="";
if (file.isEmpty()) {
throw new RRException("上传文件不能为空");
}
try{
url = url.replaceAll("/", "\\\\");
String fileName = file.getOriginalFilename();
int i=fileName.lastIndexOf(".");
String newext = fileName.substring(i);
SimpleDateFormat simpleDateFormat;
simpleDateFormat = new SimpleDateFormat("yyyyMMdd_hhmmss");
Date date = new Date();
newFileName ="图片_"+simpleDateFormat.format(date)+"_"+file.getSize()+newext;
File file3 = new File(url);
if ((!file3.exists()) && (!file3.isDirectory())) {
file3.mkdir();
}
File file2 = new File(file3, fileName);
File file2 = new File(file3, newFileName);
InputStream in = file.getInputStream();
FileOutputStream fos = new FileOutputStream(file2);
BufferedOutputStream bos = new BufferedOutputStream(fos);
......@@ -246,7 +257,7 @@ public class JgSubjectController extends AbstractController {
} catch (Exception e) {
e.printStackTrace();
}
return R.ok();
return R.ok().put("filename", newFileName);
}
/**
......
......@@ -5,6 +5,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
......@@ -25,16 +27,26 @@ public class SysOssController {
@RequestMapping("/ToLeadImg")
public R ToLeadImg(String editorid, @RequestParam("upfile") MultipartFile file, HttpServletRequest request, HttpServletResponse response) throws IOException {
String path = "";
String newFileName="";
try {
//path = request.getSession().getServletContext().getRealPath("statics/plugins/umeditor/docroot/attachments/article/");
path ="C:/document/attachments/";
path = path.replaceAll("/", "\\\\");
String fileName = file.getOriginalFilename();
String fileName = file.getOriginalFilename();
int i=fileName.lastIndexOf(".");
String newext = fileName.substring(i);
SimpleDateFormat simpleDateFormat;
simpleDateFormat = new SimpleDateFormat("yyyyMMdd_hhmmss");
Date date = new Date();
newFileName ="图片_"+simpleDateFormat.format(date)+"_"+file.getSize()+newext;
File file3 = new File(path);
if ((!file3.exists()) && (!file3.isDirectory())) {
file3.mkdir();
}
File file2 = new File(file3, fileName);
File file2 = new File(file3, newFileName);
InputStream in = file.getInputStream();
FileOutputStream fos = new FileOutputStream(file2);
BufferedOutputStream bos = new BufferedOutputStream(fos);
......@@ -50,7 +62,7 @@ public class SysOssController {
} catch (Exception e) {
e.printStackTrace();
}
return R.ok().put("url","docroot/attachments/article/"+file.getOriginalFilename());
return R.ok().put("url","docroot/attachments/article/"+newFileName);
}
@RequestMapping("/ToLead")
public String imgController(Map<String, Object> params) {
......
......@@ -182,8 +182,7 @@
<div class="form-group">
<div class="col-sm-2 control-label">附件</div>
<div class="col-sm-10">
<el-upload
class="upload-demo"
<el-upload class="upload-demo"
action="../jk/jgsubject/uploadfile"
:on-exceed="handleExceed"
:on-preview="handlePreview"
......@@ -195,8 +194,6 @@
<el-button size="small" type="primary">点击上传</el-button>
<div slot="tip" class="el-upload__tip">只能上传10个文件,且单个文件不超过10M</div>
</el-upload>
<!--<input type="text" class="form-control" v-model="jgSubject.file" style="display:none"/>
<div id="file" class="dropzone" style="border: 1px solid #ccc;width:300px;height:30px;float: left;"></div>-->
</div>
</div>
<div class="form-group">
......
......@@ -80,13 +80,16 @@ $(function () {
this.on("addedfile", function(file) {
});
this.on("success", function(file) {
photo=file.name;
this.on("success", function(file,data) {
console.log(data)
console.log(file)
photo=data.filename;
isUsedPhotoOrFile=true;
});
this.on("removedfile", function(file) {
var fileName = file.name;
remove(fileName)
photo=null;
//var fileName = file.name;
//remove(fileName)
});
}
});
......@@ -107,8 +110,8 @@ $(function () {
isUsedPhotoOrFile=true;
});
this.on("removedfile", function(file) {
var fileName = file.name;
remove(fileName)
//var fileName = file.name;
//remove(fileName)
});
}
});
......@@ -210,6 +213,7 @@ var vm = new Vue({
vm.reload();
},
add: function(){
vm.fileList = [];
isUsedPhotoOrFile=false;
vm.showList = false;
vm.title = "新增";
......@@ -355,6 +359,7 @@ var vm = new Vue({
});
},
reload: function (event) {
vm.fileList = [];
if(isUsedPhotoOrFile){
window.location.reload();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment