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

fix: apply correct mimeType in iOS #1023

Merged
merged 7 commits into from
Nov 21, 2023
Merged

fix: apply correct mimeType in iOS #1023

merged 7 commits into from
Nov 21, 2023

Conversation

acezard
Copy link
Contributor

@acezard acezard commented Nov 21, 2023

This PR will fix:

  • Incorrect video/picture names on iOS
  • Crash on mespapiers on iOS
  • Incorrect encoded names (%20 instead of spaces) on iOS
  • Empty iOS uploads
  • Wrong file type on Drive upload (iOS)

},
status: OsReceiveFileStatus.toUpload,
type: file.mimeType
type: 'application/pdf'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about jpg/mov or else? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch wasn't supposed to be there at all. I guess the unit test failed at detecting it, I'm going to update it too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we check the iOS code to see why we can't rely on the mimeType? It sounds weird 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well in iOS the mimetype is just ".pdf" for pdf for instance. The stack does not recognize it and the file has no icon. (not really breaking in itself). On Android the mimeType has the expected web format

},
status: OsReceiveFileStatus.toUpload,
type: file.mimeType
type: 'application/pdf'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'application/pdf' here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to remove it when I switched from the mac to the PC 🤦

@@ -12,6 +13,8 @@ import {
ReceivedFile,
OS_RECEIVE_PROTOCOL_NAME
} from '/app/domain/osReceive/models/ReceivedFile'
import { Media } from '/app/domain/backup/models'
import { getMimeType } from '/app/domain/backup/services/getMedias'
Copy link
Contributor

@zatteo zatteo Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to write it down because I did not think about it before, but we should move getMimeType from backup service to upload service one day.

@acezard acezard force-pushed the fix--iOS-upload-issues branch from d942558 to 456c9b4 Compare November 21, 2023 09:08
@acezard acezard requested review from Crash-- and zatteo November 21, 2023 09:08
Directly in file creation so no need to update it later.
Also ensure file name and file path are decoded URI to avoid
encoded spaces (%20) or other encoded characters by the import lib
@acezard acezard force-pushed the fix--iOS-upload-issues branch from 456c9b4 to 9f6c286 Compare November 21, 2023 09:41
Name was an UUID for images & videos, now using real name
Also removing file:// prefix in filepaths as it made RNFS
unable to retrieve the file, and silently creating empty files
@acezard acezard force-pushed the fix--iOS-upload-issues branch from 7c122d4 to 54328e9 Compare November 21, 2023 15:19
Still keeping our app as safeguard precaution for now.
If the mimetype is correct it adds no overhead since it will pass it
through
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
.appendingPathComponent("\(newName).\(fileExtension)")
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(this.hostAppBundleIdentifier)")!
.appendingPathComponent(originalFileName) // Use the original file name
Copy link
Contributor Author

@acezard acezard Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is incorrect, fixing it (fixed)


const createOsReceiveFile = (file: ReceivedFile): OsReceiveFile => {
const decodedFileName = decodeFileName(file.fileName)
const mimeType = determineMimeType(file.fileName, file.mimeType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember there was a diff on checking mimeType for Android received files and for iOS received files, did you check that on both platform?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember there was a diff on checking mimeType for Android received files and for iOS received files, did you check that on both platform?

yes, on Android I just use mimeType directly since it's correct. Only on iOS I try to guess it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok and so there is no diff on the name part?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only on iOS I try to guess it

Don't you fixed that here? https://github.com/cozy/cozy-flagship-app/pull/1023/files#diff-e5fbd9f4b85d62986896fb1d8408ad2d8d5a0f2267b5e0b22a9caef7c97255bb

that's true, the Platform checking is then redundant

@acezard acezard requested a review from Ldoppea November 21, 2023 15:36
@acezard acezard force-pushed the fix--iOS-upload-issues branch 2 times, most recently from abb6232 to 5d2c98f Compare November 21, 2023 16:30
Will use mimeType for both ios and android
since the  share lib is patched
Still include failsafe
@acezard acezard force-pushed the fix--iOS-upload-issues branch from 5d2c98f to 7a4133b Compare November 21, 2023 16:40
This patch wasn't needed.
It competes with the other patch we implemented in clearReceivedFiles
We have to let it be so the event handlers respond
correctly to file sharing
@acezard acezard merged commit bdc22d9 into master Nov 21, 2023
1 check passed
@acezard acezard deleted the fix--iOS-upload-issues branch November 21, 2023 17:18
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.

4 participants