use of org.springframework.web.multipart.MultipartFile in project gocd by gocd.
the class ArtifactsController method updateChecksumFile.
private boolean updateChecksumFile(MultipartHttpServletRequest request, JobIdentifier jobIdentifier, String filePath) throws IOException, IllegalArtifactLocationException {
MultipartFile checksumMultipartFile = getChecksumFile(request);
if (checksumMultipartFile != null) {
String checksumFilePath = String.format("%s/%s/%s", artifactsService.findArtifactRoot(jobIdentifier), ArtifactLogUtil.CRUISE_OUTPUT_FOLDER, ArtifactLogUtil.MD5_CHECKSUM_FILENAME);
File checksumFile = artifactsService.getArtifactLocation(checksumFilePath);
synchronized (checksumFilePath.intern()) {
return artifactsService.saveOrAppendFile(checksumFile, checksumMultipartFile.getInputStream());
}
} else {
LOGGER.warn("[Artifacts Upload] Checksum file not uploaded for artifact at path '{}'", filePath);
}
return true;
}
use of org.springframework.web.multipart.MultipartFile in project gocd by gocd.
the class FakeArtifactPublisherServlet method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
MultipartHttpServletRequest httpServletRequest = multipartResolver.resolveMultipart(request);
Map<String, MultipartFile> map = httpServletRequest.getFileMap();
MultipartFile multipartFile = map.values().iterator().next();
receivedFiles.add(multipartFile.getOriginalFilename());
}
use of org.springframework.web.multipart.MultipartFile in project disconf by knightliao.
the class FileUploadValidator method validateFiles.
/**
* 验证文件大小,文件名,文件后缀
*
* @param files
* @param maxLength
* @param allowExtName
*
* @return
*/
public List<MultipartFile> validateFiles(List<MultipartFile> files, long maxLength, String[] allowExtName) {
List<MultipartFile> retFiles = new ArrayList<MultipartFile>();
for (MultipartFile multipartFile : files) {
try {
this.validateFile(multipartFile, maxLength, allowExtName);
retFiles.add(multipartFile);
} catch (Exception e) {
LOG.warn(e.toString());
}
}
return retFiles;
}
use of org.springframework.web.multipart.MultipartFile in project scoold by Erudika.
the class AdminController method restore.
@PostMapping("/import")
public String restore(@RequestParam("file") MultipartFile file, @RequestParam(required = false, defaultValue = "false") Boolean isso, HttpServletRequest req, HttpServletResponse res) {
Profile authUser = utils.getAuthUser(req);
if (!utils.isAdmin(authUser)) {
res.setStatus(403);
return null;
}
ObjectReader reader = ParaObjectUtils.getJsonMapper().readerFor(new TypeReference<List<Map<String, Object>>>() {
});
Map<String, String> comments2authors = new LinkedHashMap<>();
int count = 0;
int importBatchSize = Config.getConfigInt("import_batch_size", 100);
String filename = file.getOriginalFilename();
Sysprop s = new Sysprop();
s.setType("scooldimport");
try (InputStream inputStream = file.getInputStream()) {
if (StringUtils.endsWithIgnoreCase(filename, ".zip")) {
try (ZipInputStream zipIn = new ZipInputStream(inputStream)) {
ZipEntry zipEntry;
List<ParaObject> toCreate = new LinkedList<ParaObject>();
while ((zipEntry = zipIn.getNextEntry()) != null) {
if (isso) {
count += importFromSOArchive(zipIn, zipEntry, reader, comments2authors).size();
} else if (zipEntry.getName().endsWith(".json")) {
List<Map<String, Object>> objects = reader.readValue(new FilterInputStream(zipIn) {
public void close() throws IOException {
zipIn.closeEntry();
}
});
objects.forEach(o -> toCreate.add(ParaObjectUtils.setAnnotatedFields(o)));
if (toCreate.size() >= importBatchSize) {
pc.createAll(toCreate);
toCreate.clear();
}
count += objects.size();
} else {
logger.error("Expected JSON but found unknown file type to import: {}", zipEntry.getName());
}
}
if (!toCreate.isEmpty()) {
pc.createAll(toCreate);
}
if (isso) {
updateSOCommentAuthors(comments2authors);
}
}
} else if (StringUtils.endsWithIgnoreCase(filename, ".json")) {
List<Map<String, Object>> objects = reader.readValue(inputStream);
List<ParaObject> toCreate = new LinkedList<ParaObject>();
objects.forEach(o -> toCreate.add(ParaObjectUtils.setAnnotatedFields(o)));
count = objects.size();
pc.createAll(toCreate);
}
s.setCreatorid(authUser.getCreatorid());
s.setName(authUser.getName());
s.addProperty("count", count);
s.addProperty("file", filename);
logger.info("Imported {} objects to {}. Executed by {}", count, Config.getConfigParam("access_key", "scoold"), authUser.getCreatorid() + " " + authUser.getName());
if (count > 0) {
pc.create(s);
}
} catch (Exception e) {
logger.error("Failed to import " + filename, e);
return "redirect:" + ADMINLINK + "?error=true&imported=" + count;
}
return "redirect:" + ADMINLINK + "?success=true&imported=" + count;
}
use of org.springframework.web.multipart.MultipartFile in project java-chassis by ServiceComb.
the class UploadSchema method fileUpload.
@PostMapping(path = "/fileUpload", produces = MediaType.TEXT_PLAIN_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public String fileUpload(@RequestPart(name = "files") List<MultipartFile> files) {
try {
String fileName = UUID.randomUUID().toString();
List<File> savedFiles = new ArrayList<>();
int index = 0;
for (MultipartFile file : files) {
File tempFile = new File("random-server-" + fileName + index);
savedFiles.add(tempFile);
file.transferTo(tempFile);
index++;
}
savedFiles.forEach(file -> file.delete());
return "success";
} catch (IOException e) {
return "failed";
}
}
Aggregations