Skip to content

Commit 44fc4ea

Browse files
Set spring properties to allow 16MB (Medium BLOB size) uploads (#495)
* Set spring properties to allow 16MB (Medium BLOB size) uploads * Inform users why their upload has failed * Adjust file limit to mediumblob specification
1 parent 9d9ddfd commit 44fc4ea

File tree

3 files changed

+54
-11
lines changed

3 files changed

+54
-11
lines changed

user-interface/src/main/java/life/qbic/datamanager/views/projects/purchase/UploadPurchaseDialog.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.vaadin.flow.component.html.Div;
1010
import com.vaadin.flow.component.html.Paragraph;
1111
import com.vaadin.flow.component.html.Span;
12+
import com.vaadin.flow.component.upload.FailedEvent;
13+
import com.vaadin.flow.component.upload.FileRejectedEvent;
1214
import com.vaadin.flow.component.upload.SucceededEvent;
1315
import com.vaadin.flow.component.upload.Upload;
1416
import com.vaadin.flow.dom.DomEvent;
@@ -20,6 +22,8 @@
2022
import java.util.List;
2123
import life.qbic.application.commons.ApplicationException;
2224
import life.qbic.datamanager.views.general.DialogWindow;
25+
import life.qbic.datamanager.views.notifications.ErrorMessage;
26+
import life.qbic.datamanager.views.notifications.StyledNotification;
2327
import life.qbic.datamanager.views.projects.EditableMultiFileMemoryBuffer;
2428
import life.qbic.logging.api.Logger;
2529
import life.qbic.projectmanagement.application.purchase.OfferDTO;
@@ -35,14 +39,15 @@ public class UploadPurchaseDialog extends DialogWindow {
3539

3640
private static final Logger log = logger(UploadPurchaseDialog.class);
3741
private static final String VAADIN_FILENAME_EVENT = "event.detail.file.name";
38-
private static final int MAX_FILE_SIZE_BYTES = 1024 * 1024 * 5; // 14 MiB
42+
private static final int MAX_FILE_SIZE_BYTES = 1024 * 1024 * 16; // 16 MiB
3943
@Serial
4044
private static final long serialVersionUID = 6602134795666762831L;
4145
private final Upload upload;
42-
private EditableMultiFileMemoryBuffer multiFileMemoryBuffer;
46+
private final EditableMultiFileMemoryBuffer multiFileMemoryBuffer;
4347
private final Div uploadedPurchaseItems;
4448
private final List<PurchaseItem> purchaseItemsCache = new ArrayList<>();
4549
private final Div uploadedItemsSectionContent;
50+
4651
public UploadPurchaseDialog() {
4752
// Vaadin's upload component setup
4853
multiFileMemoryBuffer = new EditableMultiFileMemoryBuffer();
@@ -66,7 +71,6 @@ public UploadPurchaseDialog() {
6671
Div uploadSection = new Div();
6772
uploadSection.add(uploadSectionTitle, upload, restrictions);
6873

69-
7074
// Uploaded purchase items display configuration
7175
uploadedPurchaseItems = new Div();
7276
uploadedPurchaseItems.addClassName("uploaded-purchase-items");
@@ -85,6 +89,10 @@ public UploadPurchaseDialog() {
8589
// Add upload offers to the purchase item section, where users can set the signed flag
8690
upload.addSucceededListener(this::onUploadSucceeded);
8791

92+
// Show notification if user provides invalid file
93+
upload.addFailedListener(this::onUploadFailure);
94+
upload.addFileRejectedListener(this::onUploadFailure);
95+
8896
// Synchronise the Vaadin upload component with the purchase list display
8997
// When a file is removed from the upload component, we also want to remove it properly from memory
9098
// and from any additional display
@@ -106,6 +114,20 @@ private void onUploadSucceeded(SucceededEvent succeededEvent) {
106114
toggleFileSectionIfEmpty();
107115
}
108116

117+
private void onUploadFailure(ComponentEvent<Upload> event) {
118+
ErrorMessage errorMessage = new ErrorMessage("Offer upload failed",
119+
"An unknown exception has occurred");
120+
if (event instanceof FileRejectedEvent) {
121+
errorMessage.descriptionTextSpan.setText(
122+
"Please provide a file within the file limit of %s MB".formatted(
123+
MAX_FILE_SIZE_BYTES / (1024 * 1024)));
124+
} else if (event instanceof FailedEvent) {
125+
errorMessage.descriptionTextSpan.setText("Offer upload was interrupted, please try again");
126+
}
127+
StyledNotification notification = new StyledNotification(errorMessage);
128+
notification.open();
129+
}
130+
109131
@Override
110132
protected void onConfirmClicked(ClickEvent<Button> clickEvent) {
111133
fireEvent(new ConfirmEvent(this, true));

user-interface/src/main/java/life/qbic/datamanager/views/projects/qualityControl/UploadQualityControlDialog.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.vaadin.flow.component.html.Div;
1010
import com.vaadin.flow.component.html.Paragraph;
1111
import com.vaadin.flow.component.html.Span;
12+
import com.vaadin.flow.component.upload.FailedEvent;
13+
import com.vaadin.flow.component.upload.FileRejectedEvent;
1214
import com.vaadin.flow.component.upload.SucceededEvent;
1315
import com.vaadin.flow.component.upload.Upload;
1416
import com.vaadin.flow.dom.DomEvent;
@@ -21,6 +23,8 @@
2123
import java.util.Objects;
2224
import life.qbic.application.commons.ApplicationException;
2325
import life.qbic.datamanager.views.general.DialogWindow;
26+
import life.qbic.datamanager.views.notifications.ErrorMessage;
27+
import life.qbic.datamanager.views.notifications.StyledNotification;
2428
import life.qbic.datamanager.views.projects.EditableMultiFileMemoryBuffer;
2529
import life.qbic.datamanager.views.projects.qualityControl.QualityControlItem.ExperimentItem;
2630
import life.qbic.logging.api.Logger;
@@ -32,13 +36,12 @@
3236
* <b>Upload Quality Control Dialog</b>
3337
* <p>
3438
* A dialog window that enables uploads of sample quality control reports.
35-
*
3639
*/
3740
public class UploadQualityControlDialog extends DialogWindow {
3841

3942
private static final Logger log = logger(UploadQualityControlDialog.class);
4043
private static final String VAADIN_FILENAME_EVENT = "event.detail.file.name";
41-
private static final int MAX_FILE_SIZE_BYTES = 1024 * 1024 * 16; // 16 MiB
44+
private static final int MAX_FILE_SIZE_BYTES = 1024 * 1024 * 16; // 17 MiB
4245
@Serial
4346
private static final long serialVersionUID = 6602134795666762831L;
4447
private final Upload upload;
@@ -60,7 +63,6 @@ public UploadQualityControlDialog(ProjectId projectId,
6063

6164
// Vaadin's upload component setup
6265
multiFileMemoryBuffer = new EditableMultiFileMemoryBuffer();
63-
6466
upload = new Upload(multiFileMemoryBuffer);
6567
upload.setAcceptedFileTypes(AllowedFileExtension.PDF.extension(),
6668
AllowedFileExtension.PDF.mimetype(),
@@ -78,7 +80,7 @@ public UploadQualityControlDialog(ProjectId projectId,
7880
restrictions.addClassName("restrictions");
7981
restrictions.add(new Span("Supported file formats: PDF, docx, xlsx"));
8082
restrictions.add(
81-
new Span("Maximum file size: %s MB" .formatted(MAX_FILE_SIZE_BYTES / (1024 * 1024))));
83+
new Span("Maximum file size: %s MB".formatted(MAX_FILE_SIZE_BYTES / (1024 * 1024))));
8284
Div uploadSection = new Div();
8385
uploadSection.add(uploadSectionTitle, upload, restrictions);
8486

@@ -100,6 +102,10 @@ public UploadQualityControlDialog(ProjectId projectId,
100102
// Add upload QualityControls to the link experiment item section, where users can decide on the linked experiment
101103
upload.addSucceededListener(this::onUploadSucceeded);
102104

105+
// Show notification if user provides invalid file
106+
upload.addFailedListener(this::onUploadFailure);
107+
upload.addFileRejectedListener(this::onUploadFailure);
108+
103109
// Synchronise the Vaadin upload component with the purchase list display
104110
// When a file is removed from the upload component, we also want to remove it properly from memory
105111
// and from any additional display
@@ -122,6 +128,21 @@ private void onUploadSucceeded(SucceededEvent succeededEvent) {
122128
toggleFileSectionIfEmpty();
123129
}
124130

131+
private void onUploadFailure(ComponentEvent<Upload> event) {
132+
ErrorMessage errorMessage = new ErrorMessage("Quality Control upload failed",
133+
"An unknown exception has occurred");
134+
if (event instanceof FileRejectedEvent) {
135+
errorMessage.descriptionTextSpan.setText(
136+
"Please provide a file within the file limit of %s MB".formatted(
137+
MAX_FILE_SIZE_BYTES / (1024 * 1024)));
138+
} else if (event instanceof FailedEvent) {
139+
errorMessage.descriptionTextSpan.setText(
140+
"Quality control upload was interrupted, please try again");
141+
}
142+
StyledNotification notification = new StyledNotification(errorMessage);
143+
notification.open();
144+
}
145+
125146
@Override
126147
protected void onConfirmClicked(ClickEvent<Button> clickEvent) {
127148
fireEvent(new ConfirmEvent(this, true));

user-interface/src/main/resources/application.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ qbic.broadcasting.identity.topic=User
9595
###############################################################################
9696
################### File Upload ###############################################
9797
# Upload file size configuration
98-
# Currently 5 MiB (mebibyte, base-2)
99-
spring.servlet.multipart.max-file-size=5242880
100-
spring.servlet.multipart.fileSizeThreshold=6MB
101-
spring.servlet.multipart.max-request-size=6MB
98+
# Currently 16 MiB due to mediumblob specification in database (mebibyte, base-2)
99+
spring.servlet.multipart.max-file-size=16777216
100+
spring.servlet.multipart.fileSizeThreshold=16MB
101+
spring.servlet.multipart.max-request-size=16MB
102102
###############################################################################
103103
################### Dev Tools #################################################
104104
spring.devtools.livereload.enabled=true

0 commit comments

Comments
 (0)