在Android上的Chrome(最新版本,两者)中从网页读取音频文件时,碰巧<input type="file" accept="audio/*">
中的文件名缺少文件扩展名。
我需要确定它是否真的是音频文件,以及它可能具有的扩展名。
有没有简单的方法可以做到这一点?
编辑:如果我用例如Google的文件查找,则文件具有正确的文件扩展名。但是我目前正在尝试解决Android上的Chrome浏览器中的一些错误。 (如果时间不长,我将有时间提交另一个错误报告。)
最佳答案
您可以从input
的文件列表中检查文件的类型
let fileinput = document.querySelector('input[type="file"]');
let button = document.querySelector('button');
button.addEventListener('click', function(){
if(fileinput.files !== null){
if(/audio\/*/.test(fileinput.files[0]['type']) === true){
let getExtension = fileinput.files[0]['name'].split('.');
alert(`This is an audio file and the extension for this file is ${getExtension[getExtension.length - 1]}`)
}else{
alert('Nope')
}
}else{
alert('Pick a file')
}
})
<input type="file" multiple="false" accept="audio/*">
<button>Is this a Audio File ?</button>
关于javascript - 如何确定音频文件扩展名可能是什么(Chrome,Android)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61480472/