|
@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Date;
|
|
@@ -29,7 +30,7 @@ import java.util.concurrent.ExecutorService;
|
|
|
public class QuestionController {
|
|
|
@Resource
|
|
|
private QuestionService questionService;
|
|
|
- @Resource
|
|
|
+// @Resource
|
|
|
private UploadProperties properties;
|
|
|
@Resource
|
|
|
private ExecutorService executorService;
|
|
@@ -66,18 +67,21 @@ public class QuestionController {
|
|
|
})
|
|
|
public Result uploadQuestion(Long pid, Integer section, @RequestParam(required = false) Integer number,
|
|
|
@RequestBody MultipartFile file) throws Exception {
|
|
|
- String date = DateUtil.format(new Date(), "yyMMdd_HHmmss_");
|
|
|
+// String date = DateUtil.format(new Date(), "yyMMdd_HHmmss_");
|
|
|
//暂时缓存到本地
|
|
|
- String saveName = properties.getUploadLocation() + date + file.getOriginalFilename();
|
|
|
- byte[] data = file.getBytes();
|
|
|
- byte[] clone = data.clone();
|
|
|
- executorService.submit(() -> {
|
|
|
- try {
|
|
|
- FileCopyUtils.copy(clone, new File(saveName));
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- });
|
|
|
+// String saveName = properties.getUploadLocation() + date + file.getOriginalFilename();
|
|
|
+// byte[] data = file.getBytes();
|
|
|
+// byte[] clone = data.clone();
|
|
|
+// executorService.submit(() -> {
|
|
|
+// try {
|
|
|
+// FileCopyUtils.copy(clone, new File(saveName));
|
|
|
+// } catch (IOException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// });
|
|
|
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
+ FileCopyUtils.copy(file.getInputStream(), baos);
|
|
|
+ byte[] data = baos.toByteArray();
|
|
|
return questionService.parseQuestion(pid, section, number, data);
|
|
|
}
|
|
|
}
|