Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 22 additions & 2 deletions src/AjaxUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

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.

Copy link
Contributor Author

@divyeshagrawal divyeshagrawal Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot from 2025-12-13 19-54-43

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.

});
}),
);

return cachedFiles as RcFile[];
}

return [];
};

uploadFiles = async (files: File[]) => {
const originFiles = await this.cacheFiles(files);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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[];

const postFiles = originFiles.map((file: RcFile & { uid?: string }) => {
// eslint-disable-next-line no-param-reassign
file.uid = getUid();
Expand Down
Loading