diff --git a/src/main/java/ru/ulstu/file/service/FileService.java b/src/main/java/ru/ulstu/file/service/FileService.java index e0d9813..3a68bb6 100644 --- a/src/main/java/ru/ulstu/file/service/FileService.java +++ b/src/main/java/ru/ulstu/file/service/FileService.java @@ -34,7 +34,6 @@ public class FileService { FileData fileData = new FileData(); fileData.setData(getTmpFile(tmpFileName)); fileData.setSize(getTmpFileSize(tmpFileName)); - fileData.setName(getTmpFileName(tmpFileName)); fileData.setCreateDate(new Date()); return fileRepository.save(fileData); } @@ -99,16 +98,18 @@ public class FileService { @Transactional public FileData create(FileDataDto fileDataDto) { - FileData newFile = copyFromDto(new FileData(), fileDataDto); + FileData newFile = new FileData(); + try { + newFile = createFileFromTmp(fileDataDto.getTmpFileName()); + } catch (IOException e) { + } + copyFromDto(newFile, fileDataDto); newFile = fileRepository.save(newFile); return newFile; } private FileData copyFromDto(FileData fileData, FileDataDto fileDataDto) { - fileData.setCreateDate(fileDataDto.getCreateDate()); - fileData.setData(fileDataDto.getData()); fileData.setName(fileDataDto.getName()); - fileData.setSize(fileDataDto.getSize()); return fileData; } diff --git a/src/main/resources/public/js/file-loader.js b/src/main/resources/public/js/file-loader.js index 9ee16a1..1ba467b 100644 --- a/src/main/resources/public/js/file-loader.js +++ b/src/main/resources/public/js/file-loader.js @@ -42,6 +42,7 @@ function FileLoader(args) { div.append(fileLabel); var fileInput = $("") .attr("type", "file") + .attr("multiple", '') .hide(); fileInput.change(function () { var files = $(this).prop("files"); @@ -75,20 +76,22 @@ function FileLoader(args) { showFeedbackMessage(ALERT_CHOOSE_FILE, MessageTypesEnum.DANGER); return; } - var currentFile = files[0]; - if (!isEmpty(fileExtensions) && fileExtensions.indexOf(getFileExt(currentFile)) === -1) { - showFeedbackMessage(ALERT_UNKNOWN_FILE_EXT, MessageTypesEnum.DANGER); - return; + for (var i = 0; i < files.length; i++) { + var currentFile = files[i]; + if (!isEmpty(fileExtensions) && fileExtensions.indexOf(getFileExt(currentFile)) === -1) { + showFeedbackMessage(ALERT_UNKNOWN_FILE_EXT, MessageTypesEnum.DANGER); + return; + } + if (currentFile.size === 0) { + showFeedbackMessage(ALERT_EMPTY_FILE, MessageTypesEnum.DANGER); + return; + } + if (MAX_FILE_SIZE_MB != -1 && currentFile.size / SIZE_TO_MB > MAX_FILE_SIZE_MB) { + showFeedbackMessage(ALERT_MAX_FILE + " " + MAX_FILE_SIZE_MB + "Mb", MessageTypesEnum.DANGER); + return; + } + upload(currentFile); } - if (currentFile.size === 0) { - showFeedbackMessage(ALERT_EMPTY_FILE, MessageTypesEnum.DANGER); - return; - } - if (currentFile.size / SIZE_TO_MB > MAX_FILE_SIZE_MB) { - showFeedbackMessage(ALERT_MAX_FILE + " " + MAX_FILE_SIZE_MB + "Mb", MessageTypesEnum.DANGER); - return; - } - upload(currentFile); }); buttonGroup.append(uploadButton); diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index d758bb9..996c991 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -190,7 +190,7 @@ new FileLoader({ div: "loader", url: urlFileUpload, - maxSize: 1.5, + maxSize: -1, extensions: [], callback: function (response) { showFeedbackMessage("Файл успешно загружен"); @@ -227,14 +227,14 @@ var nameInput = $("") .attr("type", "hidden") .attr("id", "files" + fileNumber + ".name") - .attr("value", tmpFileName[1]) + .attr("value", fileNames[1]) .attr("name", "files[" + fileNumber + "].name"); newFileRow.append(nameInput); var tmpFileNameInput = $("") .attr("type", "hidden") .attr("id", "files" + fileNumber + ".tmpFileName") - .attr("value", tmpFileName[0]) + .attr("value", fileNames[0]) .attr("name", "files[" + fileNumber + "].tmpFileName"); newFileRow.append(tmpFileNameInput); @@ -251,7 +251,7 @@ var nameDiv = $("
") .addClass("col-10") - .append($("").text(tmpFileName[1])); + .append($("").text(fileNames[1])); newFileRow.append(nameDiv); $("#files-list").append(newFileRow);