如何从 Javascript FileReader 获取文件名? [英] How to get the filename from the Javascript FileReader?

查看:40
本文介绍了如何从 Javascript FileReader 获取文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Javascript FileReader 在浏览器中加载图像:

I'm using the Javascript FileReader to load an image in the browser:

e = e.originalEvent;
e.dataTransfer.dropEffect = 'copy';
this.documentFile = e.dataTransfer.files[0];

var reader = new FileReader();
reader.onloadend = function () {
    if (reader.result) {
        console.log(reader);
        $('#theImage').attr('src', reader.result);
    }
};
reader.readAsDataURL(this.documentFile);

这很好用.我现在想获取图像的原始文件名,但我不知道如何浏览互联网我也找不到任何东西?

This works fine. I now want to get the original filename of the image, but I've got no clue how and looking around the internet I can't find anything either?

有人知道如何通过 FileReader 获取文件名吗?欢迎所有提示!

Does anybody know how I can get the filename through the FileReader? All tips are welcome!

推荐答案

这可能不是最好的解决方案,但它对我有用.

This is prob not the best solution, BUT it worked for me.

var reader = new FileReader();
reader.fileName = file.name // file came from a input file element. file = el.files[0];
reader.onload = function(readerEvt) {
    console.log(readerEvt.target.fileName);
};

不是最佳答案,而是可行的答案.

Not the best answer, but a working one.

这篇关于如何从 Javascript FileReader 获取文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆