-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Scan - No error modal shown after selecting corrupted image. #40162
Changes from 3 commits
7cf12f5
3f819b8
a7a7729
5e41d85
dc28844
028748b
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -237,7 +237,7 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s | |||||||||
|
||||||||||
const validateAndCompleteAttachmentSelection = useCallback( | ||||||||||
(fileData: FileResponse) => { | ||||||||||
if (fileData.width === -1 || fileData.height === -1) { | ||||||||||
if (fileData.width === -1 || fileData.height === -1 || (fileData.height === 0 && fileData.width === 0)) { | ||||||||||
Krishna2323 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
showImageCorruptionAlert(); | ||||||||||
return Promise.resolve(); | ||||||||||
} | ||||||||||
|
@@ -283,16 +283,20 @@ function AttachmentPicker({type = CONST.ATTACHMENT_PICKER_TYPE.FILE, children, s | |||||||||
}; | ||||||||||
/* eslint-enable @typescript-eslint/prefer-nullish-coalescing */ | ||||||||||
if (fileDataName && Str.isImage(fileDataName)) { | ||||||||||
ImageSize.getSize(fileDataUri).then(({width, height}) => { | ||||||||||
fileDataObject.width = width; | ||||||||||
fileDataObject.height = height; | ||||||||||
validateAndCompleteAttachmentSelection(fileDataObject); | ||||||||||
}); | ||||||||||
ImageSize.getSize(fileDataUri) | ||||||||||
.then(({width, height}) => { | ||||||||||
fileDataObject.width = width; | ||||||||||
fileDataObject.height = height; | ||||||||||
validateAndCompleteAttachmentSelection(fileDataObject); | ||||||||||
}) | ||||||||||
.catch(() => { | ||||||||||
showImageCorruptionAlert(); | ||||||||||
}); | ||||||||||
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. NAB: could you please update this?
Suggested change
|
||||||||||
} else { | ||||||||||
return validateAndCompleteAttachmentSelection(fileDataObject); | ||||||||||
} | ||||||||||
}, | ||||||||||
[validateAndCompleteAttachmentSelection], | ||||||||||
[validateAndCompleteAttachmentSelection, showImageCorruptionAlert], | ||||||||||
); | ||||||||||
|
||||||||||
/** | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import Str from 'expensify-common/lib/str'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import {Alert, Linking, Platform} from 'react-native'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import ImageSize from 'react-native-image-size'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import type {FileObject} from '@components/AttachmentModal'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import DateUtils from '@libs/DateUtils'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import * as Localize from '@libs/Localize'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
import Log from '@libs/Log'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -238,6 +241,21 @@ function base64ToFile(base64: string, filename: string): File { | |||||||||||||||||||||||||||||||||||||||||||||||||||
return file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
function checkIfImageIsCorrupted(file: FileObject) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
return new Promise((resolve, reject) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!Str.isImage(file.name ?? '')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
resolve(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
ImageSize.getSize(file.uri ?? '') | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.then(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
resolve(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
.catch(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
reject(new Error(`'Error reading file: The file is corrupted`)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
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. Let's better go this way:
Suggested change
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. done! 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. 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. Sure, will keep this in mind from next time. I appreciate the tip :) |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
showGeneralErrorAlert, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
showSuccessAlert, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -250,4 +268,5 @@ export { | |||||||||||||||||||||||||||||||||||||||||||||||||||
appendTimeToFileName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
readFileAsync, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
base64ToFile, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
checkIfImageIsCorrupted, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
}; |
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.
Is this some edge case when
fileData.height === 0 && fileData.width === 0
?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.
Yeah, on ios native the image width/height for corrupted image is 0 and on android native it is -1.
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.
@paultsimura, you mean you are unable to find corrupted image on ios attachment picker or something else?
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.
Sorry, I've removed the previous comment – finally figured out how to upload the corrupted image into my simulator