use of org.springframework.web.multipart.MultipartFile in project Assignment by WMPeople.
the class RestController method updateWithoutAttachment.
/**
* 게시물에 첨부파일을 유지하고 싶은 경우를 제외하고는 글수정 데이터를 받아 DB에 등록합니다.
* @param board 사용자가 수정한 board 데이터를 받습니다.
* @param attachment 첨부파일 데이터를 받습니다.
*/
@RequestMapping(value = "/boards/update2", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> updateWithoutAttachment(BoardDTO board, MultipartHttpServletRequest attachment) {
Map<String, Object> resultMap = new HashMap<>();
MultipartFile mFile = null;
Iterator<String> iter = attachment.getFileNames();
while (iter.hasNext()) {
String uploadFile_name = iter.next();
mFile = attachment.getFile(uploadFile_name);
}
try {
if (mFile != null) {
if (!mFile.getOriginalFilename().equals("")) {
FileDTO file = new FileDTO();
file.setFile_name(mFile.getOriginalFilename());
file.setFile_data(mFile.getBytes());
file.setFile_size(mFile.getSize());
fileMapper.createFile(file);
board.setFile_id(file.getFile_id());
}
}
NodePtrDTO leapPtrDTO = new NodePtrDTO(board.getBoard_id(), board.getVersion());
NodePtrDTO newNode = versionManagementService.modifyVersion(board, leapPtrDTO);
if (newNode == null) {
resultMap.put("result", "수정 실패");
} else {
resultMap.put("result", "success");
}
} catch (Exception e) {
resultMap.put("result", e.getMessage());
e.printStackTrace();
return resultMap;
}
return resultMap;
}
use of org.springframework.web.multipart.MultipartFile in project Assignment by WMPeople.
the class RestController method create.
/**
* 글 생성을 합니다. VersionManagementService의 createArticle 함수를 호출하여 board_histry 테이블과 board 테이블에 데이터를 삽입합니다.
* @param board 사용자가 작성한 board 데이터를 받습니다.
* @param attachment 첨부파일 데이터를 받습니다.
*/
@RequestMapping(value = "/boards", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> create(BoardDTO board, MultipartHttpServletRequest attachment) {
Map<String, Object> resultMap = new HashMap<>();
MultipartFile mFile = null;
Iterator<String> iter = attachment.getFileNames();
while (iter.hasNext()) {
String uploadFile_name = iter.next();
mFile = attachment.getFile(uploadFile_name);
}
try {
if (mFile != null) {
if (!mFile.getOriginalFilename().equals("")) {
FileDTO file = new FileDTO();
file.setFile_name(mFile.getOriginalFilename());
file.setFile_data(mFile.getBytes());
file.setFile_size(mFile.getSize());
fileMapper.createFile(file);
board.setFile_id(file.getFile_id());
} else {
board.setFile_id(0);
}
}
versionManagementService.createArticle(board);
resultMap.put("result", "success");
} catch (Exception e) {
// TODO: handle exception
resultMap.put("result", e.getMessage());
e.printStackTrace();
}
return resultMap;
}
use of org.springframework.web.multipart.MultipartFile in project CzechIdMng by bcvsolutions.
the class CsvConnectorTypeTest method testDeployCsv.
@Test
public void testDeployCsv() throws IOException {
String csvName = "idm_test.csv";
ConnectorTypeDto mockCsvConnectorTypeDto = new ConnectorTypeDto();
mockCsvConnectorTypeDto.setReopened(false);
mockCsvConnectorTypeDto.setId(CsvConnectorType.NAME);
ConnectorTypeDto csvConnectorTypeDto = connectorManager.load(mockCsvConnectorTypeDto);
assertNotNull(csvConnectorTypeDto);
String defaultPath = csvConnectorTypeDto.getMetadata().get(CsvConnectorType.FILE_PATH);
assertNotNull(defaultPath);
// Convert test file to the bytes and create mock MultipartFile.
byte[] bytes = Files.readAllBytes(Paths.get(CSV_TEST_FILE));
MultipartFile multipartFile = new MockMultipartFile(csvName, bytes);
// Deploy file. CSV file should be copied to the default path.
ResponseEntity<ConnectorTypeDto> deployResponse = csvConnectorTypeController.deploy(csvName, defaultPath, multipartFile);
ConnectorTypeDto deployResult = deployResponse.getBody();
assertNotNull(deployResult);
assertEquals(Paths.get(defaultPath, csvName).toString(), Paths.get(deployResult.getMetadata().get(CsvConnectorType.FILE_PATH)).toString());
// Check if deployed file exists.
assertTrue(Files.exists(Paths.get(defaultPath, csvName)));
}
use of org.springframework.web.multipart.MultipartFile in project xmall by Exrick.
the class ImageController method uploadFile.
@RequestMapping(value = "/image/imageUpload", method = RequestMethod.POST)
@ApiOperation(value = "WebUploader图片上传")
public Result<Object> uploadFile(@RequestParam("file") MultipartFile files, HttpServletRequest request) {
String imagePath = null;
// 文件保存路径
String filePath = request.getSession().getServletContext().getRealPath("/upload") + "\\" + QiniuUtil.renamePic(files.getOriginalFilename());
// 转存文件
try {
// 保存至服务器
File file = new File((filePath));
files.transferTo(file);
// 上传七牛云服务器
imagePath = QiniuUtil.qiniuUpload(filePath);
if (imagePath.contains("error")) {
throw new XmallUploadException("上传失败");
}
// 路径为文件且不为空则进行删除
if (file.isFile() && file.exists()) {
file.delete();
}
} catch (Exception e) {
e.printStackTrace();
}
return new ResultUtil<Object>().setData(imagePath);
}
use of org.springframework.web.multipart.MultipartFile in project xmall by Exrick.
the class ImageController method kindeditor.
@RequestMapping(value = "/kindeditor/imageUpload", method = RequestMethod.POST)
@ApiOperation(value = "KindEditor图片上传")
public KindEditorResult kindeditor(@RequestParam("imgFile") MultipartFile files, HttpServletRequest request) {
KindEditorResult kindEditorResult = new KindEditorResult();
// 文件保存路径
String filePath = request.getSession().getServletContext().getRealPath("/upload") + "\\" + QiniuUtil.renamePic(files.getOriginalFilename());
// 检查文件
String message = QiniuUtil.isValidImage(request, files);
if (!message.equals("valid")) {
kindEditorResult.setError(1);
kindEditorResult.setMessage(message);
return kindEditorResult;
}
// 转存文件
try {
// 保存至服务器
File file = new File((filePath));
files.transferTo(file);
// 上传七牛云服务器
String imagePath = QiniuUtil.qiniuUpload(filePath);
if (imagePath.contains("error")) {
kindEditorResult.setError(1);
kindEditorResult.setMessage("上传失败");
return kindEditorResult;
}
// 路径为文件且不为空则进行删除
if (file.isFile() && file.exists()) {
file.delete();
}
kindEditorResult.setError(0);
kindEditorResult.setUrl(imagePath);
return kindEditorResult;
} catch (IOException e) {
e.printStackTrace();
}
kindEditorResult.setError(1);
kindEditorResult.setMessage("上传失败");
return kindEditorResult;
}
Aggregations