#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 fileData = new FileData();
|
||||||
fileData.setData(getTmpFile(tmpFileName));
|
fileData.setData(getTmpFile(tmpFileName));
|
||||||
fileData.setSize(getTmpFileSize(tmpFileName));
|
fileData.setSize(getTmpFileSize(tmpFileName));
|
||||||
fileData.setName(getTmpFileName(tmpFileName));
|
|
||||||
fileData.setCreateDate(new Date());
|
fileData.setCreateDate(new Date());
|
||||||
return fileRepository.save(fileData);
|
return fileRepository.save(fileData);
|
||||||
}
|
}
|
||||||
@ -99,16 +98,18 @@ public class FileService {
|
|||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public FileData create(FileDataDto fileDataDto) {
|
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);
|
newFile = fileRepository.save(newFile);
|
||||||
return newFile;
|
return newFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileData copyFromDto(FileData fileData, FileDataDto fileDataDto) {
|
private FileData copyFromDto(FileData fileData, FileDataDto fileDataDto) {
|
||||||
fileData.setCreateDate(fileDataDto.getCreateDate());
|
|
||||||
fileData.setData(fileDataDto.getData());
|
|
||||||
fileData.setName(fileDataDto.getName());
|
fileData.setName(fileDataDto.getName());
|
||||||
fileData.setSize(fileDataDto.getSize());
|
|
||||||
return fileData;
|
return fileData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ function FileLoader(args) {
|
|||||||
div.append(fileLabel);
|
div.append(fileLabel);
|
||||||
var fileInput = $("<input>")
|
var fileInput = $("<input>")
|
||||||
.attr("type", "file")
|
.attr("type", "file")
|
||||||
|
.attr("multiple", '')
|
||||||
.hide();
|
.hide();
|
||||||
fileInput.change(function () {
|
fileInput.change(function () {
|
||||||
var files = $(this).prop("files");
|
var files = $(this).prop("files");
|
||||||
@ -75,20 +76,22 @@ function FileLoader(args) {
|
|||||||
showFeedbackMessage(ALERT_CHOOSE_FILE, MessageTypesEnum.DANGER);
|
showFeedbackMessage(ALERT_CHOOSE_FILE, MessageTypesEnum.DANGER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var currentFile = files[0];
|
for (var i = 0; i < files.length; i++) {
|
||||||
if (!isEmpty(fileExtensions) && fileExtensions.indexOf(getFileExt(currentFile)) === -1) {
|
var currentFile = files[i];
|
||||||
showFeedbackMessage(ALERT_UNKNOWN_FILE_EXT, MessageTypesEnum.DANGER);
|
if (!isEmpty(fileExtensions) && fileExtensions.indexOf(getFileExt(currentFile)) === -1) {
|
||||||
return;
|
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);
|
buttonGroup.append(uploadButton);
|
||||||
|
|
||||||
|
@ -190,7 +190,7 @@
|
|||||||
new FileLoader({
|
new FileLoader({
|
||||||
div: "loader",
|
div: "loader",
|
||||||
url: urlFileUpload,
|
url: urlFileUpload,
|
||||||
maxSize: 1.5,
|
maxSize: -1,
|
||||||
extensions: [],
|
extensions: [],
|
||||||
callback: function (response) {
|
callback: function (response) {
|
||||||
showFeedbackMessage("Файл успешно загружен");
|
showFeedbackMessage("Файл успешно загружен");
|
||||||
@ -227,14 +227,14 @@
|
|||||||
var nameInput = $("<input/>")
|
var nameInput = $("<input/>")
|
||||||
.attr("type", "hidden")
|
.attr("type", "hidden")
|
||||||
.attr("id", "files" + fileNumber + ".name")
|
.attr("id", "files" + fileNumber + ".name")
|
||||||
.attr("value", tmpFileName[1])
|
.attr("value", fileNames[1])
|
||||||
.attr("name", "files[" + fileNumber + "].name");
|
.attr("name", "files[" + fileNumber + "].name");
|
||||||
newFileRow.append(nameInput);
|
newFileRow.append(nameInput);
|
||||||
|
|
||||||
var tmpFileNameInput = $("<input/>")
|
var tmpFileNameInput = $("<input/>")
|
||||||
.attr("type", "hidden")
|
.attr("type", "hidden")
|
||||||
.attr("id", "files" + fileNumber + ".tmpFileName")
|
.attr("id", "files" + fileNumber + ".tmpFileName")
|
||||||
.attr("value", tmpFileName[0])
|
.attr("value", fileNames[0])
|
||||||
.attr("name", "files[" + fileNumber + "].tmpFileName");
|
.attr("name", "files[" + fileNumber + "].tmpFileName");
|
||||||
newFileRow.append(tmpFileNameInput);
|
newFileRow.append(tmpFileNameInput);
|
||||||
|
|
||||||
@ -251,7 +251,7 @@
|
|||||||
|
|
||||||
var nameDiv = $("<div/>")
|
var nameDiv = $("<div/>")
|
||||||
.addClass("col-10")
|
.addClass("col-10")
|
||||||
.append($("<div/>").text(tmpFileName[1]));
|
.append($("<div/>").text(fileNames[1]));
|
||||||
newFileRow.append(nameDiv);
|
newFileRow.append(nameDiv);
|
||||||
|
|
||||||
$("#files-list").append(newFileRow);
|
$("#files-list").append(newFileRow);
|
||||||
|
Loading…
Reference in New Issue
Block a user