Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(uploader): 修复选择多个文件上传只会上传一个文件的问题 Fixes #2549 #2807

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/packages/uploader/uploader.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ const InternalUploader: ForwardRefRenderFunction<
}

const readFile = <T extends TFileType>(files: T[]) => {
const results: FileItem[] = []
files.forEach((file: T, index: number) => {
let fileType = file.type
const filepath = (file.tempFilePath || file.path) as string
Expand Down Expand Up @@ -428,8 +429,9 @@ const InternalUploader: ForwardRefRenderFunction<
fileItem.url = fileType === 'video' ? file.thumbTempFilePath : filepath
}
executeUpload(fileItem, index)
setFileList([...fileList, fileItem])
results.push(fileItem)
})
setFileList([...fileList, ...results])
}

const filterFiles = <T extends TFileType>(files: T[]) => {
Expand Down
7 changes: 5 additions & 2 deletions src/packages/uploader/uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
}

const readFile = (files: File[]) => {
const results: FileItem[] = []

Check warning on line 291 in src/packages/uploader/uploader.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/uploader/uploader.tsx#L291

Added line #L291 was not covered by tests
files.forEach((file: File, index: number) => {
const formData = new FormData()
formData.append(name, file)
Expand All @@ -306,13 +307,15 @@
const reader = new FileReader()
reader.onload = (event: ProgressEvent<FileReader>) => {
fileItem.url = (event.target as FileReader).result as string
setFileList([...fileList, fileItem])
// setFileList([...fileList, fileItem])
results.push(fileItem)

Check warning on line 311 in src/packages/uploader/uploader.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/uploader/uploader.tsx#L311

Added line #L311 was not covered by tests
}
reader.readAsDataURL(file)
} else {
setFileList([...fileList, fileItem])
results.push(fileItem)

Check warning on line 315 in src/packages/uploader/uploader.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/uploader/uploader.tsx#L315

Added line #L315 was not covered by tests
}
})
setFileList([...fileList, ...results])

Check warning on line 318 in src/packages/uploader/uploader.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/uploader/uploader.tsx#L318

Added line #L318 was not covered by tests
}

const filterFiles = (files: File[]) => {
Expand Down
Loading