Add basic file-size check.

This commit is contained in:
Chloe Herd 2023-03-22 13:44:24 -04:00
parent 3b41bb59e6
commit 0b94d83129
2 changed files with 16 additions and 3 deletions

View file

@ -95,7 +95,7 @@ export default {
cornerStyle: String, // Rounded or square. Square is default.
includeSearchIcon: Boolean,
includeImageQuestion: Boolean,
onImageQuestionSubmit: Function,
imageQuestionSubmitHandler: Function,
},
setup(props) {
const propsClone = Object.assign({}, props);
@ -136,9 +136,16 @@ export default {
},
methods: {
async imageChanged(e) {
let file = e.target.files[0];
if (!this.isImageValid(file)) {
this.$emit("imageLookupError");
return;
}
this.isImageProcessing = true;
await this.onImageQuestionSubmit(e.target.files[0])
await this.imageQuestionSubmitHandler(file)
.then(async (response) => {
this.value = response;
@ -152,6 +159,12 @@ export default {
this.isImageProcessing = false;
},
isImageValid(imageFile) {
let maxSize = 0.5 * 1028 * 1028;
return imageFile && imageFile.size < maxSize;
},
},
computed: {
questionText() {

View file

@ -21,7 +21,7 @@
maxLength="17"
:mask="vinMask"
includeImageQuestion
:onImageQuestionSubmit="getVinFromImage"
:imageQuestionSubmitHandler="getVinFromImage"
@image-lookup-error="displayVinScanAlert"
data-test="vin-lookup-field"
ref="vinLookupQuestion" />