|
|
@@ -71,7 +71,6 @@ import java.nio.file.Paths;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
-@CrossOrigin("*")
|
|
|
@RequestMapping("/onlyOffice")
|
|
|
@Controller
|
|
|
public class FileController {
|
|
|
@@ -162,6 +161,9 @@ public class FileController {
|
|
|
public String upload(@RequestParam("file") final MultipartFile file) {
|
|
|
try {
|
|
|
String userId = ContextUtil.getCurrentUserId();
|
|
|
+ if(StringUtils.isEmpty(userId)){
|
|
|
+ return "{ \"error\": \"userId is empty\"}";
|
|
|
+ }
|
|
|
|
|
|
String fullFileName = file.getOriginalFilename(); // get file name
|
|
|
String fileExtension = fileUtility.getFileExtension(fullFileName); // get file extension
|
|
|
@@ -179,14 +181,17 @@ public class FileController {
|
|
|
// if not, write an error message to the response
|
|
|
return "{ \"error\": \"File type is not supported\"}";
|
|
|
}
|
|
|
+ SimpleDateFormat df = new SimpleDateFormat("/yyyy/MMddHHmmss");//设置日期格式
|
|
|
+ String date = df.format(new Date());
|
|
|
+ fullFileName = "/template/"+userId+date+"."+fileExtension;
|
|
|
|
|
|
- String fileNamePath = storageMutator.updateFile(fullFileName, bytes); // update a file
|
|
|
+ String fileNamePath = storageMutator.updateFile(FileSystems.getDefault().getPath(storagePathBuilder.getFileLocation(fullFileName)), bytes); // update a file
|
|
|
if (StringUtils.isBlank(fileNamePath)) {
|
|
|
throw new IOException("Could not update a file"); // if the file cannot be updated, an error occurs
|
|
|
}
|
|
|
|
|
|
- fullFileName = fileUtility.getFileNameWithoutExtension(fileNamePath)
|
|
|
- + "." + fileExtension; // get full file name
|
|
|
+// fullFileName = fileUtility.getFileNameWithoutExtension(fileNamePath)
|
|
|
+// + "." + fileExtension; // get full file name
|
|
|
|
|
|
return createUserMetadata(userService.getUser(), fullFileName); // create user metadata and return it
|
|
|
} catch (Exception e) {
|