在antd react项目开发时使用upload上传组件使用fileObj[0].file取文件对象时获取不到,不能直接获取的File类型文件对象。

export interface IFileObj {
    file: IUploadFile;
    remove: () => void;
}

const handleFileListChange = useCallback((newFileList: TYPE.IFileObj[]) => {
    setFileList(newFileList);
}, [fileList]);

  <CompUpload
       fileType='file'
       onChange={ handleFileListChange }
  >
  </CompUpload>

查看源码UploadFile具体类型没有file,fileList使用originFileObj。
node_modules\antd\lib\upload\interface.d.ts

export interface UploadFile<T = any> {
    uid: string;
    size?: number;
    name: string;
    fileName?: string;
    lastModified?: number;
    lastModifiedDate?: Date;
    url?: string;
    status?: UploadFileStatus;
    percent?: number;
    thumbUrl?: string;
    crossOrigin?: React.ImgHTMLAttributes<HTMLImageElement>['crossOrigin'];
    originFileObj?: RcFile;
    response?: T;
    error?: any;
    linkProps?: any;
    type?: string;
    xhr?: T;
    preview?: string;
}

洛阳醉长安行
57 声望3 粉丝

charging...