Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

NicolasBuquet
Copy link

@NicolasBuquet NicolasBuquet commented Apr 17, 2024

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

  • I read the contributing guide
  • UI change has been tested on both light and dark themes, in portrait and landscape orientations and on iPhone and iPad simulators
  • Accessibility has been taken into account.
  • Pull request is based on the develop branch
  • Pull request contains a changelog file in ./changelog.d
  • You've made a self review of your PR
  • Pull request includes screenshots or videos of UI changes
  • Pull request includes a sign off

image

@NicolasBuquet
Copy link
Author

@pixlwave
Can you have a look at this PR ?

Copy link
Member

@pixlwave pixlwave left a 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.

Comment on lines 7728 to 7729
[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)]];
Copy link
Member

@pixlwave pixlwave May 7, 2024

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 and Maximum 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) {
Copy link
Member

@pixlwave pixlwave May 7, 2024

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;
Copy link
Member

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).

changelog.d/check_filesize_before_upload.change Outdated Show resolved Hide resolved
…ile is too big.

Signed-off-by: Nicolas Buquet <nbuquet@buquet-net.com>
Copy link

codecov bot commented May 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 12.32%. Comparing base (a5d4d1c) to head (f16203a).
Report is 41 commits behind head on develop.

Current head f16203a differs from pull request most recent head 90f1122

Please upload reports for the commit 90f1122 to get more accurate results.

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     
Flag Coverage Δ
uitests 55.67% <ø> (+0.65%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@pixlwave pixlwave left a 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.

Comment on lines +2037 to 2045
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];
Copy link
Member

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.

Comment on lines +1932 to +1935
if (filesize > maxUploadFileSize)
{
return NO;
}
Copy link
Member

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] )
Copy link
Member

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:

Suggested change
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";
Copy link
Member

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.

Copy link
Member

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.

@pixlwave
Copy link
Member

@NicolasBuquet Also, are you planning on coming back to this PR too?

@NicolasBuquet
Copy link
Author

NicolasBuquet commented Aug 14, 2024

@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.

@pixlwave pixlwave closed this Aug 14, 2024
@pixlwave
Copy link
Member

Ok, thank you for your time looking into this anyway :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants