String currentFolderStr, Boolean mark) throws Exception {
ResourceType type = ResourceType.getDefaultResourceType(typeStr);
try {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
// We upload just one file at the same time
MultipartFile uplFile = multipartRequest.getFileMap().entrySet()
.iterator().next().getValue();
// Some browsers transfer the entire source path not just the
// filename
String filename = FilenameUtils.getName(uplFile
.getOriginalFilename());
log.debug("Parameter NewFile: {}", filename);
String ext = FilenameUtils.getExtension(filename);
if (type.isDeniedExtension(ext)) {
return UploadResponse.getInvalidFileTypeError(request);
}
if (type.equals(ResourceType.IMAGE)
&& !ImageUtils.isImage(uplFile.getInputStream())) {
return UploadResponse.getInvalidFileTypeError(request);
}
String fileUrl;
CmsSite site = CmsUtils.getSite(request);
MarkConfig conf = site.getConfig().getMarkConfig();
if (mark == null) {
mark = conf.getOn();
}
boolean isImg = type.equals(ResourceType.IMAGE);
if (site.getConfig().getUploadToDb()) {
if (mark && isImg) {
File tempFile = mark(uplFile, conf);
fileUrl = dbFileMng.storeByExt(site.getUploadPath(), ext,
new FileInputStream(tempFile));
tempFile.delete();
} else {
fileUrl = dbFileMng.storeByExt(site.getUploadPath(), ext,
uplFile.getInputStream());
}
// 加上访问地址
String dbFilePath = site.getConfig().getDbFileUri();
fileUrl = request.getContextPath() + dbFilePath + fileUrl;
} else if (site.getUploadFtp() != null) {
Ftp ftp = site.getUploadFtp();
if (mark && isImg) {
File tempFile = mark(uplFile, conf);
fileUrl = ftp.storeByExt(site.getUploadPath(), ext,
new FileInputStream(tempFile));
tempFile.delete();
} else {
fileUrl = ftp.storeByExt(site.getUploadPath(), ext, uplFile
.getInputStream());
}
// 加上url前缀
fileUrl = ftp.getUrl() + fileUrl;
} else {