-
Notifications
You must be signed in to change notification settings - Fork 123
handle file upload async and sync render modes #4126
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -140,28 +140,34 @@ | |||||
|
|
||||||
| useEffect(() => { | ||||||
| if (uploadMode === 'sync' && value) { | ||||||
| const fileInfo: IStoredFile = value | ||||||
| ? { | ||||||
| // id: value.uid, | ||||||
| const isFileObject = value instanceof File || (value?.uid && value?.name && value?.size); | ||||||
|
|
||||||
| if (isFileObject) { | ||||||
| const fileInfo: IStoredFile = { | ||||||
| uid: value.uid, | ||||||
| url: null, | ||||||
| status: 'done', | ||||||
| name: value.name, | ||||||
| size: value.size, | ||||||
| type: value.type, | ||||||
| originFileObj: null, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When - originFileObj: null,
+ originFileObj: value instanceof File ? value : null,📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| } | ||||||
| : null; | ||||||
| }; | ||||||
| dispatch(fetchFileInfoSuccessAction(fileInfo)); | ||||||
| } else { | ||||||
|
|
||||||
| dispatch(fetchFileInfoSuccessAction(fileInfo)); | ||||||
| if (newFileId) { | ||||||
| fileFetcher.refetch({ queryParams: { id: newFileId } }); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| if (uploadMode === 'sync' && !Boolean(value)) { | ||||||
| dispatch(deleteFileSuccessAction()); | ||||||
| } | ||||||
| }, [uploadMode, value]); | ||||||
|
|
||||||
| useEffect(() => { | ||||||
| if (!isFetchingFileInfo && uploadMode === 'async') { | ||||||
| // Process fetch responses for async mode OR when we manually fetched in sync mode for existing files | ||||||
| if (!isFetchingFileInfo) { | ||||||
| if (isAjaxSuccessResponse(fetchingFileInfoResponse)) { | ||||||
| const fetchedFile = fetchingFileInfoResponse.result; | ||||||
| if (fetchedFile) { | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical:
uidwill beundefinedfor File instances.When
valueis aFileinstance,value.uidwill beundefinedbecause the nativeFileAPI does not include auidproperty. SinceIStoredFileextendsUploadFile(from antd), theuidis typically required for tracking files in the upload component. This will likely cause runtime issues with file display and tracking.Generate a unique
uidfor File instances:if (isFileObject) { const fileInfo: IStoredFile = { - uid: value.uid, + uid: value.uid || `sync-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`, url: null, status: 'done', name: value.name, size: value.size, type: value.type, originFileObj: null, };📝 Committable suggestion
🤖 Prompt for AI Agents