mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
fix: upload 识别图片类型逻辑错误 (#21473)
* fix: upload 识别图片类型逻辑错误 当 uploadFile 有类型时,直接对 类型 进行判断即可 * test: 增加识别文件类型的测试用例
This commit is contained in:
parent
b38ab0653c
commit
c968184348
@ -498,4 +498,12 @@ describe('Upload', () => {
|
||||
);
|
||||
errorSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('it should be treated as file but not an image', () => {
|
||||
const file = { status: 'done', uid: '-1', type: 'video/mp4', url: 'https://zos.alipayobjects.com/rmsportal/IQKRngzUuFzJzGzRJXUs.png' };
|
||||
const wrapper = mount(
|
||||
<Upload listType="picture-card" fileList={[file]} />,
|
||||
);
|
||||
expect(wrapper.find('img').length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
@ -42,11 +42,11 @@ const extname = (url: string = '') => {
|
||||
return (/\.[^./\\]*$/.exec(filenameWithoutSuffix) || [''])[0];
|
||||
};
|
||||
|
||||
const isImageFileType = (type: string): boolean => !!type && type.indexOf('image/') === 0;
|
||||
const isImageFileType = (type: string): boolean => type.indexOf('image/') === 0;
|
||||
|
||||
export const isImageUrl = (file: UploadFile): boolean => {
|
||||
if (isImageFileType(file.type)) {
|
||||
return true;
|
||||
if (file.type) {
|
||||
return isImageFileType(file.type);
|
||||
}
|
||||
const url: string = (file.thumbUrl || file.url) as string;
|
||||
const extension = extname(url);
|
||||
@ -70,7 +70,7 @@ export const isImageUrl = (file: UploadFile): boolean => {
|
||||
const MEASURE_SIZE = 200;
|
||||
export function previewImage(file: File | Blob): Promise<string> {
|
||||
return new Promise(resolve => {
|
||||
if (!isImageFileType(file.type)) {
|
||||
if (!file.type || !isImageFileType(file.type)) {
|
||||
resolve('');
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user