-
-
Notifications
You must be signed in to change notification settings - Fork 325
fix: Cloud files throwing error on upload #685
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: master
Are you sure you want to change the base?
Changes from 1 commit
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -170,8 +170,28 @@ class AjaxUploader extends Component<UploadProps> { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uploadFiles = (files: File[]) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const originFiles = [...files] as RcFile[]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cacheFiles = async (files: File[]): Promise<RcFile[]> => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (files?.length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const filesArray = [...files]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const cachedFiles = await Promise.all( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filesArray.map(async file => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const buffer = await file.arrayBuffer(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new File([buffer], file.name, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: file.type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lastModified: file.lastModified, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+178
to
+181
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new File([buffer], file.name, { | |
| type: file.type, | |
| lastModified: file.lastModified, | |
| }); | |
| const clonedFile = new File([buffer], file.name, { | |
| type: file.type, | |
| lastModified: file.lastModified, | |
| }); | |
| // Preserve additional own properties (e.g. webkitRelativePath) from the original File | |
| const ownProps = Object.getOwnPropertyNames(file); | |
| ownProps.forEach(prop => { | |
| // Skip properties already handled by the File constructor | |
| if (prop === 'name' || prop === 'type' || prop === 'lastModified' || prop === 'size') { | |
| return; | |
| } | |
| try { | |
| const desc = Object.getOwnPropertyDescriptor(file, prop); | |
| if (desc) { | |
| // Avoid redefining non-configurable properties on the cloned file | |
| Object.defineProperty(clonedFile, prop, desc); | |
| } else { | |
| (clonedFile as any)[prop] = (file as any)[prop]; | |
| } | |
| } catch { | |
| // Silently ignore properties that cannot be reassigned (e.g. read-only, non-configurable) | |
| } | |
| }); | |
| return clonedFile; |
Copilot
AI
Jan 5, 2026
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.
The uploadFiles method has been changed to async but none of its call sites await it (lines 64, 106, 114). This means errors thrown in cacheFiles or during the async upload process won't be caught properly and could result in unhandled promise rejections. The calls should either be awaited with proper error handling, or uploadFiles should handle errors internally.
Outdated
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.
The cacheFiles function is declared to return a Promise<RcFile[]>, but the File objects created inside do not have a uid property, so they are not RcFiles. Casting cachedFiles as RcFile[] on line 187 is type-unsafe. The function should promise File[] instead. The casting can be moved to uploadFiles.
Also, filesArray on line 175 is a redundant copy of the files array and can be removed.
cacheFiles = async (files: File[]): Promise<File[]> => {
if (files?.length) {
const cachedFiles = await Promise.all(
files.map(async file => {
const buffer = await file.arrayBuffer();
return new File([buffer], file.name, {
type: file.type,
lastModified: file.lastModified,
});
}),
);
return cachedFiles;
}
return [];
};
uploadFiles = async (files: File[]) => {
const originFiles = (await this.cacheFiles(files)) as RcFile[];
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.
Other file attributes would be lost.
Uh oh!
There was an error while loading. Please reload this page.
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.
I’ve attached a screenshot after printing the original and cloned File objects, and I don’t see any difference in their attributes. Please let me know if I’m missing something.