简体   繁体   English

使用来自javascript的文件填写文件上传输入

[英]Fill in a file upload input with file from javascript

so I am recording audio on my webpage using recorder.js which records audio from a mic then creates a wav file in javascript. 因此,我正在使用recorder.js在我的网页上录制音频,该文件会录制来自麦克风的音频,然后在javascript中创建一个wav文件。 I have this code to create a blob and download the file to the user's computer: 我有以下代码来创建Blob,并将文件下载到用户的计算机:

// final binary blob
var blob = new Blob ( [ view ], { type : 'audio/wav' } );

// save file locally
console.log('Handing off the file now...');
var url = (window.URL || window.webkitURL).createObjectURL(blob);
var link = window.document.createElement('a');
link.href = url;
link.download = 'output.wav';
var click = document.createEvent("Event");
click.initEvent("click", true, true);
link.dispatchEvent(click);

I was wondering if there is a way to place this file into an html file upload form input instead of downloading it to the user's computer. 我想知道是否有一种方法可以将此文件放入html文件上传表单输入中,而不是将其下载到用户计算机中。 I want to do this so that I can easily access the file in my asp.net server side code. 我想这样做,以便可以轻松访问asp.net服务器端代码中的文件。 Thank you for any help. 感谢您的任何帮助。

No, there is no possibility to initialize <input type="file"> . 不,没有可能初始化<input type="file"> This is not implemented in any known browser as it can cause security issues. 在任何已知的浏览器中均未实现此功能,因为它可能会导致安全问题。

Imagine an evil developer who makes something like this: 想象一下,一个邪恶的开发者做出这样的事情:

<input type="file" value="/etc/passwd" style="display: none;">

When the clueless user submits the form, the file is going to be uploaded and revealed to the attacker. 当无知的用户提交表单时,文件将被上传并透露给攻击者。

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

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