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;
}
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")) {
return new ResultUtil<Object>().setErrorMsg("上传失败");
}
// 路径为文件且不为空则进行删除
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 paascloud-master by paascloud.
the class OptAttachmentServiceImpl method uploadFile.
@Override
public List<OptUploadFileRespDto> uploadFile(MultipartHttpServletRequest multipartRequest, OptUploadFileReqDto optUploadFileReqDto, LoginAuthDto loginAuthDto, boolean storeDbFlag) {
String fileType = optUploadFileReqDto.getFileType();
String filePath = optUploadFileReqDto.getFilePath();
String bucketName = optUploadFileReqDto.getBucketName();
List<OptUploadFileRespDto> result = Lists.newArrayList();
if (PublicUtil.isEmpty(filePath)) {
filePath = GlobalConstant.Sys.DEFAULT_FILE_PATH;
}
try {
List<MultipartFile> fileList = multipartRequest.getFiles("file");
if (fileList.isEmpty()) {
return result;
}
for (MultipartFile multipartFile : fileList) {
String fileName = multipartFile.getOriginalFilename();
if (PublicUtil.isEmpty(fileName)) {
continue;
}
Preconditions.checkArgument(multipartFile.getSize() <= GlobalConstant.FILE_MAX_SIZE, "上传文件不能大于5M");
InputStream inputStream = multipartFile.getInputStream();
String inputStreamFileType = FileTypeUtil.getType(inputStream);
CheckFileUtil.checkFileType(fileType, inputStreamFileType);
OptUploadFileRespDto fileInfo;
if (storeDbFlag) {
fileInfo = this.uploadFile(multipartFile.getBytes(), fileName, fileType, filePath, bucketName, loginAuthDto);
} else {
fileInfo = optOssService.uploadFile(multipartFile.getBytes(), fileName, filePath, bucketName);
}
result.add(fileInfo);
}
} catch (IOException e) {
logger.error("上传文件失败={}", e.getMessage(), e);
}
return result;
}
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 ArtifactsController method postArtifact.
@RequestMapping(value = "/repository/restful/artifact/POST/*", method = RequestMethod.POST)
public ModelAndView postArtifact(@RequestParam("pipelineName") String pipelineName, @RequestParam("pipelineLabel") String counterOrLabel, @RequestParam("stageName") String stageName, @RequestParam(value = "stageCounter", required = false) String stageCounter, @RequestParam("buildName") String buildName, @RequestParam(value = "buildId", required = false) Long buildId, @RequestParam("filePath") String filePath, @RequestParam(value = "attempt", required = false) Integer attempt, MultipartHttpServletRequest request) throws Exception {
JobIdentifier jobIdentifier;
if (!headerConstraint.isSatisfied(request)) {
return ResponseCodeView.create(HttpServletResponse.SC_BAD_REQUEST, "Missing required header 'Confirm'");
}
try {
jobIdentifier = restfulService.findJob(pipelineName, counterOrLabel, stageName, stageCounter, buildName, buildId);
} catch (Exception e) {
return buildNotFound(pipelineName, counterOrLabel, stageName, stageCounter, buildName);
}
int convertedAttempt = attempt == null ? 1 : attempt;
try {
File artifact = artifactsService.findArtifact(jobIdentifier, filePath);
if (artifact.exists() && artifact.isFile()) {
return FileModelAndView.fileAlreadyExists(filePath);
}
MultipartFile multipartFile = multipartFile(request);
if (multipartFile == null) {
return FileModelAndView.invalidUploadRequest();
}
boolean success = saveFile(convertedAttempt, artifact, multipartFile, shouldUnzipStream(multipartFile));
if (!success) {
return FileModelAndView.errorSavingFile(filePath);
}
success = updateChecksumFile(request, jobIdentifier, filePath);
if (!success) {
return FileModelAndView.errorSavingChecksumFile(filePath);
}
return FileModelAndView.fileCreated(filePath);
} catch (IllegalArtifactLocationException e) {
return FileModelAndView.forbiddenUrl(filePath);
}
}
Aggregations