boolean isLocal = !(files.get(0) instanceof MultipartFile);
List<SkylineImageResizeTask> tasks = new ArrayList<SkylineImageResizeTask>(files.size());
for (Object file : files) {
long fileSize = 0L;
String filename = null;
SkylineImageResizeTask task;
if (isLocal) {
File localFile = (File) file;
fileSize = localFile.length();
filename = FilenameUtils.getName(localFile.getAbsolutePath());
} else {
MultipartFile multipartFile = (MultipartFile) file;
fileSize = multipartFile.getSize();
filename = multipartFile.getOriginalFilename();
}
if (fileSize == 0) {
continue;
}
if (fileSize > maxSizePerFile) {
message.append("上传图片" + filename + "失败,失败原因:图片太大。\n");
continue;
}
if (isLocal) {
File localFile = (File) file;
task = new LocalImageResizeTask(localFile.getAbsolutePath(), baseSizes);
} else {
MultipartFile multipartFile = (MultipartFile) file;
task = new MultipartImageResizeTask(multipartFile, baseSizes, null, false);
}
task.setUserId(userId);
task.setAlbumId(albumId);
tasks.add(task);
}
return tasks;
}