Repository navigation
fix: Profile - No error after uploading corrupted jpg for avatar, console error shows up. #49203
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
Changes from all commits
34a4d8c
5651e49
fa74969
512555d
fa96a9c
f988185
387c896
c6b7bb8
3939e4c
72cf668
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -232,26 +232,31 @@ function AvatarWithImagePicker({ | |
| return; | ||
| } | ||
|
|
||
| isValidResolution(image).then((isValid) => { | ||
| if (!isValid) { | ||
| setError('avatarWithImagePicker.resolutionConstraints', { | ||
| minHeightInPx: CONST.AVATAR_MIN_HEIGHT_PX, | ||
| minWidthInPx: CONST.AVATAR_MIN_WIDTH_PX, | ||
| maxHeightInPx: CONST.AVATAR_MAX_HEIGHT_PX, | ||
| maxWidthInPx: CONST.AVATAR_MAX_WIDTH_PX, | ||
| FileUtils.validateImageForCorruption(image) | ||
| .then(() => isValidResolution(image)) | ||
| .then((isValid) => { | ||
| if (!isValid) { | ||
| setError('avatarWithImagePicker.resolutionConstraints', { | ||
| minHeightInPx: CONST.AVATAR_MIN_HEIGHT_PX, | ||
| minWidthInPx: CONST.AVATAR_MIN_WIDTH_PX, | ||
| maxHeightInPx: CONST.AVATAR_MAX_HEIGHT_PX, | ||
| maxWidthInPx: CONST.AVATAR_MAX_WIDTH_PX, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| setIsAvatarCropModalOpen(true); | ||
| setError(null, {}); | ||
| setIsMenuVisible(false); | ||
| setImageData({ | ||
| uri: image.uri ?? '', | ||
| name: image.name ?? '', | ||
| type: image.type ?? '', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| setIsAvatarCropModalOpen(true); | ||
| setError(null, {}); | ||
| setIsMenuVisible(false); | ||
| setImageData({ | ||
| uri: image.uri ?? '', | ||
| name: image.name ?? '', | ||
| type: image.type ?? '', | ||
| }) | ||
| .catch(() => { | ||
| setError('attachmentPicker.errorWhileSelectingCorruptedAttachment', {}); | ||
| }); | ||
| }); | ||
| }, | ||
| [isValidExtension, isValidSize], | ||
| ); | ||
|
|
@@ -339,7 +344,11 @@ function AvatarWithImagePicker({ | |
| maybeIcon={isUsingDefaultAvatar} | ||
| > | ||
| {({show}) => ( | ||
| <AttachmentPicker type={CONST.ATTACHMENT_PICKER_TYPE.IMAGE}> | ||
| <AttachmentPicker | ||
| type={CONST.ATTACHMENT_PICKER_TYPE.IMAGE} | ||
| // We need to skip the validation in AttachmentPicker because it is handled in this component itself | ||
| shouldValidateImage={false} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add a comment explaining why we don't need to validate here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment added. |
||
| > | ||
| {({openPicker}) => { | ||
| const menuItems = createMenuItems(openPicker); | ||
|
|
||
|
|
@@ -383,7 +392,7 @@ function AvatarWithImagePicker({ | |
| {source ? ( | ||
| <Avatar | ||
| containerStyles={avatarStyle} | ||
| imageStyles={[avatarStyle, styles.alignSelfCenter]} | ||
| imageStyles={[styles.alignSelfCenter, avatarStyle]} | ||
| source={source} | ||
| avatarID={avatarID} | ||
| fallbackIcon={fallbackIcon} | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -255,8 +255,15 @@ function validateImageForCorruption(file: FileObject): Promise<{width: number; h | |||||||||||||||||||
| } | ||||||||||||||||||||
| return new Promise((resolve, reject) => { | ||||||||||||||||||||
| ImageSize.getSize(file.uri ?? '') | ||||||||||||||||||||
| .then(() => resolve()) | ||||||||||||||||||||
| .catch(() => reject(new Error('Error reading file: The file is corrupted'))); | ||||||||||||||||||||
| .then((size) => { | ||||||||||||||||||||
| if (size.height <= 0 || size.width <= 0) { | ||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why's this change necessary?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On native, when an image is corrupted, The same method is used here: App/src/components/AttachmentPicker/index.native.tsx Lines 272 to 280 in 37bf6b2
|
||||||||||||||||||||
| return reject(new Error('Error reading file: The file is corrupted')); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| resolve(); | ||||||||||||||||||||
| }) | ||||||||||||||||||||
| .catch(() => { | ||||||||||||||||||||
| return reject(new Error('Error reading file: The file is corrupted')); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| }); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
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.
@Ollyws, we have to skip corrupt image validation in
AttachmentPickerbecause, on native devices, we were showing an alert modal if the image was corrupt, which we don't need when usingAttachmentPickerinsideAvatarWithImagePickerbecause we already perform validation in theAvatarWithImagePickercomponent.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.
Hmm...would it make more sense to do the image validation in AttachmentPicker on both platforms?
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.
I tried, but I wasn't able to get it working. I'll try again today or tomorrow.
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.
@Ollyws, I tried and we can show the validation modal in
AttachmentPickerfor web, but I don't think it's worth it since the native validation shows only the default alert and in this case we should show the our custom modal. We can simply skip the validation in native file. WDYT?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.
@Ollyws, friendly bump to check the comment above.
Uh oh!
There was an error while loading. Please reload this page.
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.
You mean just leave the changes as they are?
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.
yep.
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.
Ok it's not a huge issue so I think it's fine as is.