简体   繁体   English

如何为 ngx-dropzone 中的非图像文件使用自定义缩略图? 角10+

[英]How do I use a custom thumbnail for non-image files in ngx-dropzone? Angular10+

So far I found one answer for JS Dropzone (older version).到目前为止,我为 JS Dropzone(旧版本)找到了一个答案。 Nothing on Angular (ngx-dropzone). Angular(ngx-dropzone)上没有任何内容。 Basically, I'm looking to add a MS Excel icon, MS Word icon, and PDF icon to the script so that when someone adds one of those filetypes it generates that thumbnail in the preview.基本上,我希望在脚本中添加一个 MS Excel 图标、MS Word 图标和 PDF 图标,以便当有人添加其中一种文件类型时,它会在预览中生成该缩略图。 It works for images out of the box.它适用于开箱即用的图像。

I inspected the code rendered and there are no indications or attributes of filetype other than the name of the file itself having a filetype associated with it (document.pdf or document.xlsx).我检查了呈现的代码,除了文件本身具有与之关联的文件类型(document.pdf 或 document.xlsx)的名称之外,没有任何文件类型的指示或属性。 Perhaps this can be done?也许这可以做到? How can I extract the filetype from the file being added and then according to that filetype, add an icon for it to the preview placeholder?如何从正在添加的文件中提取文件类型,然后根据该文件类型,将其图标添加到预览占位符?

I imagine this is where it would go?我想这就是 go 的位置?

onSelect(event) {
   this.files.push(...event.addedFiles);
}

I added a StackBlitz for a playground.我为游乐场添加了StackBlitz

Try using this for getting file type,尝试使用它来获取文件类型,

onSelect(event) {
        console.log(event.addedFiles);
    let type:any = event.addedFiles[0].name.split('.');
    type = type[type.length - 1];
    console.log(type);
    
        this.files.push(...event.addedFiles);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM