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

View file

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