use of org.springframework.web.multipart.MultipartFile in project ngtesting-platform by aaronchen2k.
the class FileUtils method SaveFile.
public static String SaveFile(MultipartFile file, String uploadRelativeDist, String fileName) {
String dateDist = DateUtils.GetDateNoSeparator();
String uploadPath = Constant.FTP_UPLOAD_DIR + uploadRelativeDist + dateDist + "/";
String localFolder = Constant.WORK_DIR + uploadPath;
FileUtils.CreateDirIfNeeded(localFolder);
String localPath = localFolder + fileName;
File localFile = new File(localPath);
try {
file.transferTo(localFile);
} catch (Exception e) {
e.printStackTrace();
return null;
}
FileUtils.Thumb(localPath);
return uploadPath + fileName;
}
use of org.springframework.web.multipart.MultipartFile in project spring-boot-quick by vector4wang.
the class Img2TxtController method imt2txt.
@RequestMapping(value = "/transfer", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<InputStreamResource> imt2txt(@RequestParam("file") MultipartFile file) {
try {
String originalFilename = file.getOriginalFilename();
HttpHeaders headers = new HttpHeaders();
// 支持jpg、png
if (originalFilename.endsWith("jpg") || originalFilename.endsWith("png")) {
File outFile = img2TxtService.save(file.getBytes(), originalFilename);
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition", String.format("attachment; filename=\"%s\"", outFile.getName()));
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
return ResponseEntity.ok().headers(headers).contentLength(outFile.length()).contentType(MediaType.parseMediaType("application/octet-stream")).body(new InputStreamResource(new FileInputStream(outFile)));
} else {
File error = new File(img2TxtService.getErrorPath());
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition", String.format("attachment; filename=\"%s\"", error.getName()));
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
return ResponseEntity.ok().headers(headers).contentLength(error.length()).contentType(MediaType.parseMediaType("application/octet-stream")).body(new InputStreamResource(new FileInputStream(error)));
}
} catch (IOException e) {
logger.error(e);
return new ResponseEntity("暂不支持的文件格式", HttpStatus.BAD_REQUEST);
}
// return new ResponseEntity(HttpStatus.BAD_REQUEST);
}
use of org.springframework.web.multipart.MultipartFile in project rpki-validator-3 by RIPE-NCC.
the class TrustAnchorController method add.
@PostMapping(path = "/upload", consumes = "multipart/form-data")
public ResponseEntity<ApiResponse<TrustAnchorResource>> add(@RequestParam("file") MultipartFile trustAnchorLocator, Locale locale) {
try {
TrustAnchorLocator locator = TrustAnchorLocator.fromMultipartFile(trustAnchorLocator);
AddTrustAnchor command = AddTrustAnchor.builder().type(TrustAnchor.TYPE).name(locator.getCaName()).locations(locator.getCertificateLocations().stream().map(URI::toASCIIString).collect(Collectors.toList())).subjectPublicKeyInfo(locator.getPublicKeyInfo()).rsyncPrefetchUri(locator.getPrefetchUris().stream().filter(uri -> "rsync".equalsIgnoreCase(uri.getScheme())).map(URI::toASCIIString).findFirst().orElse(null)).build();
long id = trustAnchorService.execute(command);
TrustAnchor trustAnchor = trustAnchorRepository.get(id);
Link selfRel = linkTo(methodOn(TrustAnchorController.class).get(id, locale)).withSelfRel();
return ResponseEntity.created(URI.create(selfRel.getHref())).body(trustAnchorResource(trustAnchor, locale));
} catch (TrustAnchorExtractorException ex) {
return ResponseEntity.badRequest().body(ApiResponse.error(ApiError.of(HttpStatus.BAD_REQUEST, "Invalid trust anchor locator: " + ex.getMessage())));
}
}
use of org.springframework.web.multipart.MultipartFile in project metalnx-web by irods-contrib.
the class TemplateController method importXMLFile.
@RequestMapping(value = "/import/", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public String importXMLFile(final Model model, final HttpServletRequest request, final RedirectAttributes redirect) {
String responseString = "ok";
if (request instanceof MultipartHttpServletRequest) {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
List<MultipartFile> multipartFiles = multipartRequest.getFiles("file");
String prefix = multipartRequest.getParameter("prefix");
String suffix = multipartRequest.getParameter("suffix");
try {
String username = loggedUserUtils.getLoggedDataGridUser().getUsername();
boolean result = templateService.importXmlMetadataTemplate(multipartFiles.get(0).getInputStream(), username, prefix, suffix);
if (!result) {
responseString = "partial";
}
} catch (JAXBException | IOException | DataGridException e) {
logger.error("Could not import metadata templates", e);
responseString = "error";
}
}
return responseString;
}
use of org.springframework.web.multipart.MultipartFile in project metalnx-web by irods-contrib.
the class TicketClientController method upload.
@RequestMapping(value = "/{ticketstring}", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void upload(@PathVariable("ticketstring") final String ticketString, final HttpServletRequest request) throws DataGridConnectionRefusedException, DataGridTicketUploadException, IOException, DataGridTicketInvalidUserException {
logger.info("Uploading files using ticket: {}", ticketString);
if (!(request instanceof MultipartHttpServletRequest)) {
logger.error("Request is not a multipart request. Stop.");
return;
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile multipartFile = multipartRequest.getFile("file");
String destPath = multipartRequest.getParameter("path");
File file = multipartToFile(multipartFile);
ticketClientService.transferFileToIRODSUsingTicket(ticketString, file, destPath);
}
Aggregations