文件读取器API不给音频文件放置

发布于 2025-01-24 11:46:08 字数 5908 浏览 1 评论 0原文

作为A 的一部分,在上传控件之前,我检查是否添加的文件实际上与它们扩展所描述的FileType相匹配。

我使用隐藏的元素进行filecheck。如果失败,则在formdata附加后将其删除。

我也在后端检查文件,但我也想通过文件读取器进程检查。 createItemsReadItems等所有功能都在所有其他情况下都起作用,这意味着它们返回 null 的输出true false 。当我从图像和视频文件中获取输出时,音频文件根本没有。它应该起作用。

问题是:
文件读取器是否读取audio文件与视频>image> image文件?

以下只是实际代码的一个小块。
现在的问题是:为什么它不返回音频文件上的输出?

  • Quest0& QUEST1是UI元素。这是我从中获取文件的元素。
  • 读取器是“新的filereader”。
  • what.filecount在页面init作为ReadOnly属性时添加。
  • ReadItems在所有类似的文件上都提供输出,

但是如果文件类型为AUDIO/,则UI HTML不会更新?

for (var oD = 0; oD < what.files.length; oD++) 
{
    var pL = false;
    if (typeof window.dofile === 'undefined' || !window.dofile) { return; }
    
    if (file_s.exec(file) && !what.multiple) { pL = true; }
    else 
    {
        if (what.files.length > what.filecount) 
        {
            alert('too many files added. only ' + what.filecount + ' are allowed.');
            what.value = '';
            
            if (quest0 != null) 
            { quest0.innerHTML = ('too many files added. only ' + what.filecount + ' are allowed.'); }
            
            return;
        }
        
        pL = true;
        if ( !lastform.includes(what.form.id) ) { pL = false; }
    }
    
    if (what.files && what.files[oD] && pL == true) 
    {
        if (file_prev != null) 
        {
            if (file_prev.getAttribute('data-src') == '') 
            {file_prev.setAttribute('data-src', file_prev.src); }
            
            file_prev.src = file_backsrc;
        }
        
        reader.onload = function(e) 
        {
            init();
            
            if (typeof file_prev === 'undefined') 
            {
                if (quest1 != null) { quest1.innerHTML = 'Error occoured'; }
                return;
            }
            
            if (file_p == 'img' || file_p == 'video' || file_p == 'audio') 
            { file_prev.src = e.target.result; }
            
            if (file_p == 'canvas') { /*not yet*/ }
            
            kill.classList.remove('invisible');
            
            if (quest1 != null) { quest1.innerHTML = 'file done'; }
        }
        
        reader.onerror = function(e) 
        {
            e.preventDefault();
            alert('There was an error with one of your file(s). Filename ' + what.files[oD].name + '');
            what.value = '';
        }

        function waitfor(arr) 
        {
            if (arr == null || arr.length == 0) { return; }
           
            var aL = arr.length,
                aL0 = arr.shift();
           
            file_prev = _(aL0.file_prev);
            lastfile = aL0.lastfile;
            file_p = aL0.file_p;

            reader.readAsDataURL(aL0.file);
            aL0.kill.classList.add('invisible');
            setTimeout(() => {
                                init();
                                waitfor(arr)
                             }, 1250);
            
            if (quest1 != null) 
            { quest1.innerHTML = 'processing ' + file_p; }
        }
        
        if (what.multiple) 
        {
            var oA = 0;
            lastfile = what.files[oD].name;
            
            for (oA; oA < dK.children.length; oA++) 
            {
                var oB = what.files[oD], oB0, oB1;
                    
                if (oB.type.includes('im')) { file_p = 'img'; }
                if (oB.type.includes('au')) { file_p = 'audio'; }
                if (oB.type.includes('vi')) { file_p = 'video'; }
                
                if (lastfile != what.files[oD].name || lastfilearr.length <= what.filecount) 
                {
                    oB0 = dK.children[oA];
                    if (oB0.nodeName.toLowerCase() == file_p && what.form.querySelectorAll(file_p)[oD] != null)
                    {
                        if ( /*oB0.getAttribute('data-src')==''&&*/ !lastfilearr.includes(what.files[oD].name)) 
                        {
                            oB0 = what.form.querySelectorAll(file_p)[oD];
                            file_prev = oB0;
                            lastfilearr.push(what.files[oD].name);
                            oB0.setAttribute('data-src', lastfile);
                            
                            oB1 = new Object({
                                                'file_prev': file_prev.id,
                                                'file_p': file_p,
                                                'file': what.files[oD],
                                                'kill': kill
                                            });
                            
                            stoargearr.push(oB1);
                            createtoast(['Filechecker', 'the ' + what.files[oD].name + ' is getting checked.', 3e3, true, true, ['bg-info', 'text-dark', 'rounded', 'px-2', 'mx-1']]);
                            createItems('upload', 's', what.files[oD].name, 'name:' + what.files[oD].name + ';nr:' + oD + ';filesize:' + what.files[oD].size + ';filesizehuman:' + Math.abs(what.files[oD].size / 1024 / 1024).toFixed(2) + ';lastmodified:' + new Date(what.files[oD].lastModified).toUTCString() + ';type:' + what.files[oD].type + ';');
                        }
                    }
                }
            }
            
            if (stoargearr.length == what.files.length) { waitfor(stoargearr); }
            else { reader.readAsDataURL(what.files[oD]); }
        }
    }
}

“文件读取器API”在音频文件上是否像在视频或图像文件上一样反应?

感谢您的帮助。

As a part of a before upload control, I check if added files actually match the filetype that their extension describes.

I do a filecheck using a hidden element. and if it fails, it gets removed after formdata append.

I check the files at the backend too, but I also want to check via File Reader process. All functions like createItems or readItems and so on, are working in all other cases, meaning that they return output of either null, true or false. While I get output from image and video files, audio files not at all. It should work.

The question is:
Does the file reader read audio files differently compared to video and image files?

The following is only a tiny block of the actual code.
Now the question is: Why it doesn't return output on audio files?.

  • quest0 & quest1 are UI elements. Which is the element that I pull the files from.
  • reader is "new FileReader".
  • what.filecount is added while page init as readonly property.
  • readItems gives output on all kind off files,

However the UI html doesn't get updated if it is the file type is audio/?

for (var oD = 0; oD < what.files.length; oD++) 
{
    var pL = false;
    if (typeof window.dofile === 'undefined' || !window.dofile) { return; }
    
    if (file_s.exec(file) && !what.multiple) { pL = true; }
    else 
    {
        if (what.files.length > what.filecount) 
        {
            alert('too many files added. only ' + what.filecount + ' are allowed.');
            what.value = '';
            
            if (quest0 != null) 
            { quest0.innerHTML = ('too many files added. only ' + what.filecount + ' are allowed.'); }
            
            return;
        }
        
        pL = true;
        if ( !lastform.includes(what.form.id) ) { pL = false; }
    }
    
    if (what.files && what.files[oD] && pL == true) 
    {
        if (file_prev != null) 
        {
            if (file_prev.getAttribute('data-src') == '') 
            {file_prev.setAttribute('data-src', file_prev.src); }
            
            file_prev.src = file_backsrc;
        }
        
        reader.onload = function(e) 
        {
            init();
            
            if (typeof file_prev === 'undefined') 
            {
                if (quest1 != null) { quest1.innerHTML = 'Error occoured'; }
                return;
            }
            
            if (file_p == 'img' || file_p == 'video' || file_p == 'audio') 
            { file_prev.src = e.target.result; }
            
            if (file_p == 'canvas') { /*not yet*/ }
            
            kill.classList.remove('invisible');
            
            if (quest1 != null) { quest1.innerHTML = 'file done'; }
        }
        
        reader.onerror = function(e) 
        {
            e.preventDefault();
            alert('There was an error with one of your file(s). Filename ' + what.files[oD].name + '');
            what.value = '';
        }

        function waitfor(arr) 
        {
            if (arr == null || arr.length == 0) { return; }
           
            var aL = arr.length,
                aL0 = arr.shift();
           
            file_prev = _(aL0.file_prev);
            lastfile = aL0.lastfile;
            file_p = aL0.file_p;

            reader.readAsDataURL(aL0.file);
            aL0.kill.classList.add('invisible');
            setTimeout(() => {
                                init();
                                waitfor(arr)
                             }, 1250);
            
            if (quest1 != null) 
            { quest1.innerHTML = 'processing ' + file_p; }
        }
        
        if (what.multiple) 
        {
            var oA = 0;
            lastfile = what.files[oD].name;
            
            for (oA; oA < dK.children.length; oA++) 
            {
                var oB = what.files[oD], oB0, oB1;
                    
                if (oB.type.includes('im')) { file_p = 'img'; }
                if (oB.type.includes('au')) { file_p = 'audio'; }
                if (oB.type.includes('vi')) { file_p = 'video'; }
                
                if (lastfile != what.files[oD].name || lastfilearr.length <= what.filecount) 
                {
                    oB0 = dK.children[oA];
                    if (oB0.nodeName.toLowerCase() == file_p && what.form.querySelectorAll(file_p)[oD] != null)
                    {
                        if ( /*oB0.getAttribute('data-src')==''&&*/ !lastfilearr.includes(what.files[oD].name)) 
                        {
                            oB0 = what.form.querySelectorAll(file_p)[oD];
                            file_prev = oB0;
                            lastfilearr.push(what.files[oD].name);
                            oB0.setAttribute('data-src', lastfile);
                            
                            oB1 = new Object({
                                                'file_prev': file_prev.id,
                                                'file_p': file_p,
                                                'file': what.files[oD],
                                                'kill': kill
                                            });
                            
                            stoargearr.push(oB1);
                            createtoast(['Filechecker', 'the ' + what.files[oD].name + ' is getting checked.', 3e3, true, true, ['bg-info', 'text-dark', 'rounded', 'px-2', 'mx-1']]);
                            createItems('upload', 's', what.files[oD].name, 'name:' + what.files[oD].name + ';nr:' + oD + ';filesize:' + what.files[oD].size + ';filesizehuman:' + Math.abs(what.files[oD].size / 1024 / 1024).toFixed(2) + ';lastmodified:' + new Date(what.files[oD].lastModified).toUTCString() + ';type:' + what.files[oD].type + ';');
                        }
                    }
                }
            }
            
            if (stoargearr.length == what.files.length) { waitfor(stoargearr); }
            else { reader.readAsDataURL(what.files[oD]); }
        }
    }
}

Does the "File reader API" react different on audio files as it does on video or image files?

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薯片软お妹 2025-01-31 11:46:08

它去了。

for (var oD = 0; oD < what.files.length; oD++) {
    var pL = false;
    if (typeof window.dofile === 'undefined' || !window.dofile) {
        return;
    };
    if (file_s.exec(file) && !what.multiple) {
        pL = true;
    } else {
        if (what.files.length > what.filecount) {
            alert('too many files added. only ' + what.filecount + ' are allowed.');
            what.value = '';
            if (quest0 != null) {
                quest0.innerHTML = 'too many files added. only ' + what.filecount + ' are allowed.';
            };
            return;
        };
        pL = true;
        if (!lastform.includes(what.form.id)) {
            pL = false;
        };
    };
    if (what.files && what.files[oD] && pL == true) {
        if (file_prev != null) {
            if (file_prev.getAttribute('data-src') == '') {
                file_prev.setAttribute('data-src', file_prev.src);
            };
            file_prev.src = file_backsrc;
        };
        reader.onload = function(e) {
            init();
            if (typeof file_prev === 'undefined') {
                if (quest1 != null) {
                    quest1.innerHTML = 'Error occoured';
                };
                return;
            };
            if (file_p == 'img' || file_p == 'video' || file_p == 'audio') {
                file_prev.src = e.target.result;
            };
            if (file_p == 'canvas') { /*not yet*/ };
            kill.classList.remove('invisible');
            if (quest1 != null) {
                quest1.innerHTML = 'file done';
            };
        };
        reader.onerror = function(e) {
            e.preventDefault();
            alert('There was an error with one of your file(s). Filename ' + what.files[oD].name + '');
            what.value = '';
        };

        function waitfor(arr) {
            if (arr == null || arr.length == 0) {
                return;
            };
            var aL = arr.length,
                aL0 = arr.shift();
            file_prev = _(aL0.file_prev);
            lastfile = aL0.lastfile;
            file_p = aL0.file_p;
            reader.readAsDataURL(aL0.file);
            aL0.kill.classList.add('invisible');
            setTimeout(() => {
                init();
                waitfor(arr)
            }, 1250);
            if (quest1 != null) {
                quest1.innerHTML = 'processing ' + file_p;
            };
        };
        if (what.multiple) {
            var oA = 0;
            lastfile = what.files[oD].name;
            for (oA; oA < dK.children.length; oA++) {
                var oB = what.files[oD],
                    oB0, oB1;
                if (oB.type.includes('im')) {
                    file_p = 'img';
                };
                if (oB.type.includes('au')) {
                    file_p = 'audio';
                };
                if (oB.type.includes('vi')) {
                    file_p = 'video';
                };
                if (lastfile != what.files[oD].name || lastfilearr.length <= what.filecount) {
                    oB0 = dK.children[oA];
                    if (oB0.nodeName.toLowerCase() == file_p && what.form.querySelectorAll(file_p)[oD] != null) {
                        if ( /*oB0.getAttribute('data-src')==''&&*/ !lastfilearr.includes(what.files[oD].name)) {
                            oB0 = what.form.querySelectorAll(file_p)[oD];
                            file_prev = oB0;
                            lastfilearr.push(what.files[oD].name);
                            oB0.setAttribute('data-src', lastfile);
                            oB1 = new Object({
                                'file_prev': file_prev.id,
                                'file_p': file_p,
                                'file': what.files[oD],
                                'kill': kill
                            });
                            stoargearr.push(oB1);
                            createtoast(['Filechecker', 'the ' + what.files[oD].name + ' is getting checked.', 3e3, true, true, ['bg-info', 'text-dark', 'rounded', 'px-2', 'mx-1']]);
                            createItems('upload', 's', what.files[oD].name, 'name:' + what.files[oD].name + ';nr:' + oD + ';filesize:' + what.files[oD].size + ';filesizehuman:' + Math.abs(what.files[oD].size / 1024 / 1024).toFixed(2) + ';lastmodified:' + new Date(what.files[oD].lastModified).toUTCString() + ';type:' + what.files[oD].type + ';');
                        };
                    };
                };
            };
            if (stoargearr.length == what.files.length) {
                waitfor(stoargearr);
            };
        } else {
            reader.readAsDataURL(what.files[oD]);
        };
    };
};```

here it goes.

for (var oD = 0; oD < what.files.length; oD++) {
    var pL = false;
    if (typeof window.dofile === 'undefined' || !window.dofile) {
        return;
    };
    if (file_s.exec(file) && !what.multiple) {
        pL = true;
    } else {
        if (what.files.length > what.filecount) {
            alert('too many files added. only ' + what.filecount + ' are allowed.');
            what.value = '';
            if (quest0 != null) {
                quest0.innerHTML = 'too many files added. only ' + what.filecount + ' are allowed.';
            };
            return;
        };
        pL = true;
        if (!lastform.includes(what.form.id)) {
            pL = false;
        };
    };
    if (what.files && what.files[oD] && pL == true) {
        if (file_prev != null) {
            if (file_prev.getAttribute('data-src') == '') {
                file_prev.setAttribute('data-src', file_prev.src);
            };
            file_prev.src = file_backsrc;
        };
        reader.onload = function(e) {
            init();
            if (typeof file_prev === 'undefined') {
                if (quest1 != null) {
                    quest1.innerHTML = 'Error occoured';
                };
                return;
            };
            if (file_p == 'img' || file_p == 'video' || file_p == 'audio') {
                file_prev.src = e.target.result;
            };
            if (file_p == 'canvas') { /*not yet*/ };
            kill.classList.remove('invisible');
            if (quest1 != null) {
                quest1.innerHTML = 'file done';
            };
        };
        reader.onerror = function(e) {
            e.preventDefault();
            alert('There was an error with one of your file(s). Filename ' + what.files[oD].name + '');
            what.value = '';
        };

        function waitfor(arr) {
            if (arr == null || arr.length == 0) {
                return;
            };
            var aL = arr.length,
                aL0 = arr.shift();
            file_prev = _(aL0.file_prev);
            lastfile = aL0.lastfile;
            file_p = aL0.file_p;
            reader.readAsDataURL(aL0.file);
            aL0.kill.classList.add('invisible');
            setTimeout(() => {
                init();
                waitfor(arr)
            }, 1250);
            if (quest1 != null) {
                quest1.innerHTML = 'processing ' + file_p;
            };
        };
        if (what.multiple) {
            var oA = 0;
            lastfile = what.files[oD].name;
            for (oA; oA < dK.children.length; oA++) {
                var oB = what.files[oD],
                    oB0, oB1;
                if (oB.type.includes('im')) {
                    file_p = 'img';
                };
                if (oB.type.includes('au')) {
                    file_p = 'audio';
                };
                if (oB.type.includes('vi')) {
                    file_p = 'video';
                };
                if (lastfile != what.files[oD].name || lastfilearr.length <= what.filecount) {
                    oB0 = dK.children[oA];
                    if (oB0.nodeName.toLowerCase() == file_p && what.form.querySelectorAll(file_p)[oD] != null) {
                        if ( /*oB0.getAttribute('data-src')==''&&*/ !lastfilearr.includes(what.files[oD].name)) {
                            oB0 = what.form.querySelectorAll(file_p)[oD];
                            file_prev = oB0;
                            lastfilearr.push(what.files[oD].name);
                            oB0.setAttribute('data-src', lastfile);
                            oB1 = new Object({
                                'file_prev': file_prev.id,
                                'file_p': file_p,
                                'file': what.files[oD],
                                'kill': kill
                            });
                            stoargearr.push(oB1);
                            createtoast(['Filechecker', 'the ' + what.files[oD].name + ' is getting checked.', 3e3, true, true, ['bg-info', 'text-dark', 'rounded', 'px-2', 'mx-1']]);
                            createItems('upload', 's', what.files[oD].name, 'name:' + what.files[oD].name + ';nr:' + oD + ';filesize:' + what.files[oD].size + ';filesizehuman:' + Math.abs(what.files[oD].size / 1024 / 1024).toFixed(2) + ';lastmodified:' + new Date(what.files[oD].lastModified).toUTCString() + ';type:' + what.files[oD].type + ';');
                        };
                    };
                };
            };
            if (stoargearr.length == what.files.length) {
                waitfor(stoargearr);
            };
        } else {
            reader.readAsDataURL(what.files[oD]);
        };
    };
};```
淡看悲欢离合 2025-01-31 11:46:08
if (quest1 != null) {
                quest1.innerHTML = 'processing ' + file_p;
            };

该块在音频文件上没有输出。

if (quest1 != null) {
                quest1.innerHTML = 'processing ' + file_p;
            };

This block gives no output on audio files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文