Skip to content

Commit

Permalink
Check filesize before uploading file to server and display alert if f…
Browse files Browse the repository at this point in the history
…ile is too big.

Signed-off-by: Nicolas Buquet <[email protected]>
  • Loading branch information
Nicolas Buquet committed May 8, 2024
1 parent 087f0cc commit d24c084
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-7778.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Check filesize before uploading file to server and display alert if file is too big.

0 comments on commit d24c084

Please sign in to comment.