Skip to content

Commit

Permalink
refactor(UploadFile.vue): move readFileAsDataURL to util
Browse files Browse the repository at this point in the history
  • Loading branch information
bludnic committed Sep 17, 2024
1 parent ad14420 commit 74b0689
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/components/UploadFile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<script lang="ts">
import { defineComponent, PropType } from 'vue'
import { readFileAsDataURL } from '@/lib/file'
export type FileData = {
name: string
Expand All @@ -23,19 +24,6 @@ export type FileData = {
height?: number
}
function readFile(file: File): Promise<{ raw: Uint8Array; dataURL: string }> {
return new Promise((resolve) => {
const reader = new FileReader()
reader.onload = (e: ProgressEvent<FileReader>) => {
resolve({
raw: new Uint8Array(reader.result as ArrayBuffer),
dataURL: e.target?.result as string
})
}
reader.readAsDataURL(file)
})
}
function getImageResolution(file: File): Promise<{ width?: number; height?: number }> {
return new Promise((resolve) => {
const img = new Image()
Expand Down Expand Up @@ -75,7 +63,7 @@ export default defineComponent({
}
for (const file of selectedFiles) {
const { raw, dataURL } = await readFile(file)
const { raw, dataURL } = await readFileAsDataURL(file)
const { width, height } = await getImageResolution(file)
const fileData: FileData = {
Expand Down

0 comments on commit 74b0689

Please sign in to comment.