Skip to content

Commit

Permalink
Fix image selector fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
RemcoSimonides committed Nov 26, 2023
1 parent ac4e60e commit 7e665f8
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ImageSelectorComponent implements OnInit, OnDestroy {

step$ = this.step.asObservable()
accept = ['.jpg', '.jpeg', '.png', '.webp']
file?: File
file?: File | null
croppedImage?: Blob | null
previewUrl$ = new BehaviorSubject<string | SafeUrl>('')

Expand Down Expand Up @@ -131,10 +131,10 @@ export class ImageSelectorComponent implements OnInit, OnDestroy {
}

filesSelected(file: FileList | File) {
this.file = Array.isArray(file) ? file[0] : file
this.file = isFileList(file) ? file.item(0) : file

if (this.file?.type?.split('/')[0] !== 'image') {
this.toast.create({ message: 'Unsupported file type', duration: 3000 })
this.toast.create({ message: 'Unsupported file type', duration: 3000 }).then(toast => toast.present())
return
}

Expand Down Expand Up @@ -186,6 +186,10 @@ export class ImageSelectorComponent implements OnInit, OnDestroy {
}
}

function isFileList(file: FileList | File): file is FileList {
return (file as FileList).item !== undefined
}

function dataUrlToFile(dataUrl: string, fileName: string) {
const arr = dataUrl.split(',')
const mime = arr[0].match(/:(.*?);/)?.[1]
Expand Down

0 comments on commit 7e665f8

Please sign in to comment.