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

查看:2694
本文介绍了如何从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天全站免登陆