#13 add files to db
This commit is contained in:
parent
4fb8061653
commit
8dc5eec35c
@ -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;
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ function FileLoader(args) {
|
||||
div.append(fileLabel);
|
||||
var fileInput = $("<input>")
|
||||
.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);
|
||||
|
||||
|
@ -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 = $("<input/>")
|
||||
.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 = $("<input/>")
|
||||
.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 = $("<div/>")
|
||||
.addClass("col-10")
|
||||
.append($("<div/>").text(tmpFileName[1]));
|
||||
.append($("<div/>").text(fileNames[1]));
|
||||
newFileRow.append(nameDiv);
|
||||
|
||||
$("#files-list").append(newFileRow);
|
||||
|
Loading…
Reference in New Issue
Block a user