From d24c08422330d596cdc49c58833a32c6f8f3540d Mon Sep 17 00:00:00 2001 From: Nicolas Buquet Date: Wed, 17 Apr 2024 19:47:46 +0200 Subject: [PATCH] Check filesize before uploading file to server and display alert if file is too big. Signed-off-by: Nicolas Buquet --- Riot/Modules/Room/RoomViewController.m | 9 +++++++++ changelog.d/pr-7778.change | 1 + 2 files changed, 10 insertions(+) create mode 100644 changelog.d/pr-7778.change diff --git a/Riot/Modules/Room/RoomViewController.m b/Riot/Modules/Room/RoomViewController.m index 37cc5a7660..ffc4b5184e 100644 --- a/Riot/Modules/Room/RoomViewController.m +++ b/Riot/Modules/Room/RoomViewController.m @@ -7721,6 +7721,15 @@ - (void)documentPickerPresenter:(MXKDocumentPickerPresenter *)presenter didPickD { self.documentPickerPresenter = nil; + // Check maxUploadSize accepted by the home server before trying to upload. + NSUInteger maxUploadFileSize = self.roomDataSource.mxSession.maxUploadSize; + NSDictionary *fileAttributes = [NSFileManager.defaultManager attributesOfItemAtPath:url.path error:nil]; + if (fileAttributes && fileAttributes.fileSize > maxUploadFileSize) { + [self showAlertWithTitle:@"The file you want to upload is too big." + message:[NSString stringWithFormat:@"\nThe file you want to upload is too big.\n\nIt mustn't weight more than %ldMB", maxUploadFileSize/(1024*1024)]]; + return; + } + MXKUTI *fileUTI = [[MXKUTI alloc] initWithLocalFileURL:url]; NSString *mimeType = fileUTI.mimeType; diff --git a/changelog.d/pr-7778.change b/changelog.d/pr-7778.change new file mode 100644 index 0000000000..84c0e87b4f --- /dev/null +++ b/changelog.d/pr-7778.change @@ -0,0 +1 @@ +Check filesize before uploading file to server and display alert if file is too big. \ No newline at end of file