有的需求上传时不需要调接口但是需要展示文件,展示文件fileList需要uid,status,url,name,使用URL.createObjectURL(file)获取url,upload不使用自动上传,使用customRequest自定义请求不请求接口,如下
const uploadHandler = async (options) => {
const { onSuccess, file } = options;
if (!file) {
return false;
}
let url = URL.createObjectURL(file)
setFileList([{
uid: file?.uid, // 注意,这个uid一定不能少,否则上传失败
name: file.name,
status: 'done',
url: url, // url 是展示在页面上的绝对链接
}])
}