Skip to content

Commit 0a1f369

Browse files
debug: try to fix max request size
1 parent d3b3994 commit 0a1f369

5 files changed

Lines changed: 137 additions & 91 deletions

File tree

school_data_hub_flutter/lib/features/_schoolday_events/data/schoolday_event_api_service.dart

Lines changed: 77 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -124,88 +124,105 @@ class SchooldayEventApiService {
124124
//- an schooldayEvent can be documented with an image file of a document
125125
//- the file is encrypted before it is uploaded
126126
//- there are two possible endpoints for the file upload, depending on whether the schooldayEvent is processed or not
127-
Future<SchooldayEvent> updateSchooldayEventFile({
127+
Future<SchooldayEvent?> updateSchooldayEventFile({
128128
required int schooldayEventId,
129129
required File file,
130130
required bool isProcessed,
131131
}) async {
132-
final documentId = const Uuid().v4();
133-
final path = p.posix.join(
134-
ServerStorageFolder.events.name,
135-
'$documentId.jpg',
136-
);
137-
final uploadDescription = await _client.files.getUploadDescription(
138-
'private',
139-
path,
140-
);
141-
if (uploadDescription != null) {
142-
_log.info('Upload description received for $path');
143-
_log.fine('Upload description: $uploadDescription');
144-
// Create an uploader
145-
final uploader = FileUploader(uploadDescription);
146-
147-
// Upload the file
148-
final fileStream = file.openRead();
149-
150-
final fileLength = await file.length();
151-
_log.info('File length: $fileLength');
152-
_notificationService.apiRunning(true);
132+
try {
133+
final documentId = const Uuid().v4();
134+
final path = p.posix.join(
135+
ServerStorageFolder.events.name,
136+
'$documentId.jpg',
137+
);
138+
String? uploadDescription;
153139
try {
154-
await uploader.upload(fileStream, fileLength);
140+
uploadDescription = await _client.files.getUploadDescription(
141+
'private',
142+
path,
143+
);
155144
} catch (e) {
156145
_notificationService.apiRunning(false);
157-
_log.severe('Error while uploading file', e, StackTrace.current);
158-
159-
throw Exception('Failed to upload file, $uploadDescription');
146+
throw Exception('Failed to get upload description, $e');
160147
}
161148

162-
_notificationService.apiRunning(false);
149+
if (uploadDescription != null) {
150+
_log.info('Upload description received for $path');
151+
_log.fine('Upload description: $uploadDescription');
152+
// Create an uploader
153+
final uploader = FileUploader(uploadDescription);
163154

164-
// Verify the upload
165-
final success = await _client.files.verifyUpload('private', path);
155+
// Upload the file
156+
final fileStream = file.openRead();
166157

167-
if (success) {
158+
final fileLength = await file.length();
159+
_log.info('File length: $fileLength');
160+
_notificationService.apiRunning(true);
168161
try {
169-
final updatedSchooldayEvent = await _client.schooldayEvent
170-
.updateSchooldayEventFile(
171-
schooldayEventId,
172-
path,
173-
_hubSessionManager.userName!,
174-
isProcessed,
175-
);
176-
_notificationService.apiRunning(false);
177-
178-
return updatedSchooldayEvent;
162+
await uploader.upload(fileStream, fileLength);
179163
} catch (e) {
180164
_notificationService.apiRunning(false);
165+
_log.severe('Error while uploading file', e, StackTrace.current);
181166

182-
_log.severe(
183-
'Error while updating schoolday event file',
184-
e,
185-
StackTrace.current,
186-
);
167+
throw Exception('Failed to upload file, $uploadDescription');
168+
}
187169

188-
_notificationService.showSnackBar(
189-
NotificationType.error,
190-
'Das Profilbild konnte nicht aktualisiert werden: ${e.toString()}',
191-
);
170+
_notificationService.apiRunning(false);
171+
bool success = false;
172+
try {
173+
// Verify the upload
174+
success = await _client.files.verifyUpload('private', path);
175+
} catch (e) {
176+
_notificationService.apiRunning(false);
177+
throw Exception('Failed to verify upload, $e');
178+
}
192179

193-
throw Exception('Failed to update schoolday event file, $e');
180+
if (success) {
181+
try {
182+
final updatedSchooldayEvent = await _client.schooldayEvent
183+
.updateSchooldayEventFile(
184+
schooldayEventId,
185+
path,
186+
_hubSessionManager.userName!,
187+
isProcessed,
188+
);
189+
_notificationService.apiRunning(false);
190+
191+
return updatedSchooldayEvent;
192+
} catch (e) {
193+
_notificationService.apiRunning(false);
194+
195+
_log.severe(
196+
'Error while updating schoolday event file',
197+
e,
198+
StackTrace.current,
199+
);
200+
201+
_notificationService.showSnackBar(
202+
NotificationType.error,
203+
'Das Dokument konnte nicht aktualisiert werden: ${e.toString()}',
204+
);
205+
206+
throw Exception('Failed to update schoolday event file, $e');
207+
}
194208
}
195-
}
196-
} else {
197-
_notificationService.apiRunning(false);
209+
} else {
210+
_notificationService.apiRunning(false);
198211

199-
_log.severe('Error while uploading file', null, StackTrace.current);
212+
_log.severe('Error while uploading file', null, StackTrace.current);
200213

201-
_notificationService.showSnackBar(
202-
NotificationType.error,
203-
'Das Ereignisdokument konnte nicht hochgeladen werden: ${uploadDescription.toString()}',
204-
);
214+
_notificationService.showSnackBar(
215+
NotificationType.error,
216+
'Das Ereignisdokument konnte nicht hochgeladen werden: ${uploadDescription.toString()}',
217+
);
205218

206-
throw Exception('Failed to upload file, $uploadDescription');
219+
throw Exception('Failed to upload file, $uploadDescription');
220+
}
221+
} catch (e) {
222+
_notificationService.apiRunning(false);
223+
throw Exception('Failed to upload file, $e');
207224
}
208-
throw Exception('Failed to upload file, $uploadDescription');
225+
return null;
209226
}
210227

211228
//- delete schooldayEvent

school_data_hub_flutter/lib/features/_schoolday_events/domain/schoolday_event_manager.dart

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class SchooldayEventManager with ChangeNotifier {
9595
}
9696
}
9797

98-
//- CRUD operantions
98+
//- CRUD operantions
9999

100100
//- post schoolday event
101101

@@ -110,7 +110,9 @@ class SchooldayEventManager with ChangeNotifier {
110110

111111
_updateSchooldayEventCollections(schooldayEvent);
112112
_notificationService.showSnackBar(
113-
NotificationType.success, 'Eintrag erfolgreich!');
113+
NotificationType.success,
114+
'Eintrag erfolgreich!',
115+
);
114116

115117
return;
116118
}
@@ -125,7 +127,9 @@ class SchooldayEventManager with ChangeNotifier {
125127
updateSchooldayEventsBatchInCollections(events);
126128
} catch (e) {
127129
_notificationService.showSnackBar(
128-
NotificationType.error, 'Fehler beim Laden der Einträge: $e');
130+
NotificationType.error,
131+
'Fehler beim Laden der Einträge: $e',
132+
);
129133
}
130134
}
131135

@@ -145,54 +149,73 @@ class SchooldayEventManager with ChangeNotifier {
145149
if (processed == false && eventToUpdate.processedDocumentId != null) {
146150
cacheKey = eventToUpdate.processedDocument!.documentId;
147151
}
148-
final SchooldayEvent schooldayEvent =
149-
await _schooldayEventApiService.updateSchooldayEvent(
150-
schooldayEvent: eventToUpdate,
151-
createdBy: createdBy,
152-
reason: reason,
153-
processed: processed,
154-
processedBy: processedBy,
155-
processedAt: processedAt,
156-
schooldayId: schooldayId,
157-
type: schoolEventType);
152+
final SchooldayEvent schooldayEvent = await _schooldayEventApiService
153+
.updateSchooldayEvent(
154+
schooldayEvent: eventToUpdate,
155+
createdBy: createdBy,
156+
reason: reason,
157+
processed: processed,
158+
processedBy: processedBy,
159+
processedAt: processedAt,
160+
schooldayId: schooldayId,
161+
type: schoolEventType,
162+
);
158163

159164
_updateSchooldayEventCollections(schooldayEvent);
160165
if (cacheKey != null) {
161166
await _cacheManager.removeFile(cacheKey);
162167
}
163168
_notificationService.showSnackBar(
164-
NotificationType.success, 'Eintrag erfolgreich geändert!');
169+
NotificationType.success,
170+
'Eintrag erfolgreich geändert!',
171+
);
165172

166173
return;
167174
}
168175

169-
Future<void> updateSchooldayEventFile(
170-
{required File imageFile,
171-
required int schooldayEventId,
172-
required bool isProcessed}) async {
176+
Future<void> updateSchooldayEventFile({
177+
required File imageFile,
178+
required int schooldayEventId,
179+
required bool isProcessed,
180+
}) async {
173181
final encryptedFile = await customEncrypter.encryptFile(imageFile);
174-
final SchooldayEvent responseEvent =
175-
await _schooldayEventApiService.updateSchooldayEventFile(
176-
schooldayEventId: schooldayEventId,
177-
file: encryptedFile,
178-
isProcessed: isProcessed);
182+
final SchooldayEvent? responseEvent = await _schooldayEventApiService
183+
.updateSchooldayEventFile(
184+
schooldayEventId: schooldayEventId,
185+
file: encryptedFile,
186+
isProcessed: isProcessed,
187+
);
188+
if (responseEvent == null) {
189+
_notificationService.showSnackBar(
190+
NotificationType.error,
191+
'Datei konnte nicht hochgeladen werden!',
192+
);
193+
return;
194+
}
179195
_updateSchooldayEventCollections(responseEvent);
180196

181197
_notificationService.showSnackBar(
182-
NotificationType.success, 'Datei erfolgreich hochgeladen!');
198+
NotificationType.success,
199+
'Datei erfolgreich hochgeladen!',
200+
);
183201

184202
return;
185203
}
186204

187205
Future<void> deleteSchooldayEventFile(
188-
int schooldayEventId, String cacheKey, bool isProcessed) async {
206+
int schooldayEventId,
207+
String cacheKey,
208+
bool isProcessed,
209+
) async {
189210
final SchooldayEvent schooldayEvent = await _schooldayEventApiService
190211
.deleteSchooldayEventFile(schooldayEventId, isProcessed);
191212
await _cacheManager.removeFile(cacheKey);
192213
_updateSchooldayEventCollections(schooldayEvent);
193214

194215
_notificationService.showSnackBar(
195-
NotificationType.success, 'Datei erfolgreich gelöscht!');
216+
NotificationType.success,
217+
'Datei erfolgreich gelöscht!',
218+
);
196219

197220
return;
198221
}
@@ -210,7 +233,9 @@ class SchooldayEventManager with ChangeNotifier {
210233
removeSchooldayEventFromCollections(eventToDelete!);
211234
} catch (e) {
212235
_notificationService.showSnackBar(
213-
NotificationType.error, 'Fehler beim Löschen des Eintrags: $e');
236+
NotificationType.error,
237+
'Fehler beim Löschen des Eintrags: $e',
238+
);
214239

215240
return;
216241
}

school_data_hub_server/config/production.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# which adds SSL security through https. If you use Serverpod's standard
44
# Terraform scripts to deploy your server, all you need to change in
55
# this file is the examplepod.com domain name.
6-
maxRequestSize: 10485760
6+
77
# Configuration for the main API server.
88
apiServer:
99
port: 8080
@@ -45,3 +45,5 @@ redis:
4545
enabled: false
4646
host: redis.private-production.examplepod.com
4747
port: 6379
48+
49+
maxRequestSize: 10485760

school_data_hub_server/config/staging.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
# which adds SSL security through https. If you use Serverpod's standard
88
# Terraform scripts to deploy your server, all you need to change in
99
# this file is the examplepod.com domain name.
10-
maxRequestSize: 10485760
10+
1111
# Configuration for the main API server.
1212
apiServer:
1313
port: 8080
1414
publicHost: stagingdatahub.hermannschule.de
1515
publicPort: 443
1616
publicScheme: https
17-
maxRequestSize: 10485760 # 10 MB in bytes
17+
1818

1919
# Configuration for the Insights server.
2020
insightsServer:
@@ -49,3 +49,5 @@ redis:
4949
enabled: false
5050
host: redis.private-staging.examplepod.com
5151
port: 6379
52+
53+
maxRequestSize: 10485760

school_data_hub_server/lib/src/_features/pupil/endpooints/pupil_endpoint.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class PupilEndpoint extends Endpoint {
3434

3535
Future<List<PupilData>> fetchPupilsById(
3636
Session session, Set<int> internalIds) async {
37-
_logger.info('Fetching pupils by internal IDs: $internalIds');
37+
_logger.info('Fetching pupils by internal IDs');
3838
try {
3939
final pupils = await PupilData.db.find(
4040
session,

0 commit comments

Comments
 (0)