-
Notifications
You must be signed in to change notification settings - Fork 498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check filesize before uploading file to server and display alert if file is too big #7778
Conversation
@pixlwave |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR, it's a nice idea. There's a bit more work needed before we can merge it, comments inline.
[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)]]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few initial thoughts:
- These strings should be added to
Vector.strings
rather than hard coded. - We should use
NSByteCountFormatter
for file sizes so it is formatted properly for all locales and follows the system behaviour of reporting 1000 bytes = 1MB. - The message repeats the title. Something simple like
File too large
andMaximum supported file size: 100MB
would probably be better here.
// 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked if this takes any encryption overhead into account? Might be worth building a bit of leniency into here.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole check is in the wrong place, it doesn't account for videos and images to be processed, meaning something that would previously send, will now be rejected. It should either happen after the respective processing has taken place, or only happen for files inside the else if (fileUTI.isFile)
.
…ile is too big. Signed-off-by: Nicolas Buquet <nbuquet@buquet-net.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #7778 +/- ##
===========================================
+ Coverage 12.27% 12.32% +0.05%
===========================================
Files 1651 1651
Lines 164167 163958 -209
Branches 67499 67364 -135
===========================================
+ Hits 20148 20209 +61
+ Misses 143346 143112 -234
+ Partials 673 637 -36
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates, some more comments added inline.
if( ![self isFilesizeOkToBeSentForLocalAVAsset:videoAsset] ) | ||
{ | ||
failure([NSError errorWithDomain:MXKRoomDataSourceErrorDomain code:MXKRoomDataSourceErrorCantSendFileToBig userInfo:nil]); | ||
return; | ||
} | ||
|
||
__block MXEvent *localEchoEvent = nil; | ||
|
||
[_room sendVideoAsset:videoAsset withThumbnail:videoThumbnail threadId:self.threadId localEcho:&localEchoEvent success:success failure:failure]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @NicolasBuquet, thanks for the update. To my eyes this one still appears to be too early: MXRoom.sendVideoAsset
will convert the video meaning that the check above would block some files from sending that would have been fine.
if (filesize > maxUploadFileSize) | ||
{ | ||
return NO; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question again here:
Have you checked if this takes any encryption overhead into account? Might be worth building a bit of leniency into here.
- (BOOL)isFilesizeOkToBeSentForLocalAVAsset:(AVAsset *)asset | ||
{ | ||
// Check if asset points to a local file | ||
if( ![asset isKindOfClass:AVURLAsset.class] ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our objective-c style should look like so:
if( ![asset isKindOfClass:AVURLAsset.class] ) | |
if (![asset isKindOfClass:AVURLAsset.class]) |
There's a few of these in here.
@@ -1715,6 +1715,8 @@ Tap the + to start adding people."; | |||
// MARK: File upload | |||
"file_upload_error_title" = "File upload"; | |||
"file_upload_error_unsupported_file_type_message" = "File type not supported."; | |||
"file_upload_error_too_large_title" = "File too large"; | |||
"file_upload_error_too_large_message" = "Maximum supported file size is %@MB"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked what this looks like? Now that there's an NSByteCountFormatter
feeding the alert, it should already contain the appropriate unit formatted appropriately in the string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't make changes to the translations directly in the project - these should be added on https://translate.element.io once the PR is merged, otherwise we run the risk of handling conflicts.
@NicolasBuquet Also, are you planning on coming back to this PR too? |
Hello @pixlwave No, I don't push anymore to this PR. Too complicated. IMO, it needs changes in matrix-ios-sdk to be properly implemented. Thank you for your involvement. |
Ok, thank you for your time looking into this anyway :) |
Check filesize before uploading file to server and display alert if file is too big
This test is present in the Android version of Element, but curiously not in the iOS version.
Pull Request Checklist