async processFile()

in frontend/src/app/return-service/upload-image/upload-image.component.ts [58:103]


  async processFile(imageInput: any) {
    this.uploadingImage = true;
    const file: File = imageInput.files[0];
    const reader = new FileReader();

    await this.firebaseService.uploadReturnItemImageToStorage(file).then((snapshot) => {
      this.firebaseService.returnItemImageToDownloadURL(snapshot.metadata.name).then(
        (url) => {
          reader.addEventListener('load', () => {
            let base64string = reader.result as string;
            this.imageSource = this.sanitizer.bypassSecurityTrustResourceUrl(base64string);
            this.imagePreview = this.imageSource.changingThisBreaksApplicationSecurity
            this.imageSource = this.imageSource.changingThisBreaksApplicationSecurity.split(',')[1]
            this.imageUploaded = true;
            this.validationInprogress = true;
            this.returnService.returnValidation(this.returnItem.image, this.imageSource, "").subscribe({
              next: (data: any) => {
                this.uploadingImage = false;
                this.validationInprogress = false;
                this.returnItem.return_metadata = {
                  image_uploaded: url,
                  video_uploaded: "",
                  is_valid: data.valid,
                  ai_validation_reason: data.reasoning,
                  return_status: 'under review',
                  return_type: data.return_type,
                  returned_date: this.returnService.getYYYYMMDD(this.today)
                }
                if (data.valid) {
                  this.showAlternateProducts = true;
                } else {
                  this.updateOrder(data, url, '');
                }
              },
              error: (error) => {
                this.uploadingImage = false;
                this.validationInprogress = false;
                throw error;
              }
            });
          });
          reader.readAsDataURL(file);
        }
      )
    });
  }