作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 Matt Diamond 的 recorder.js 来浏览 HTML5 音频 API,感觉这个问题可能有明显的答案,但我找不到任何具体的文档。
问题:录制了一个wav文件后,如何通过ajax将这个wav发送到服务器?有什么建议吗???
最佳答案
如果您有 blob,则需要将其转换为 url 并通过 ajax 调用运行该 url。
// might be nice to set up a boolean somewhere if you have a handler object
object = new Object();
object.sendToServer = true;
// You can create a callback and set it in the config object.
var config = {
callback : myCallback
}
// in the callback, send the blob to the server if you set the property to true
function myCallback(blob){
if( object.sendToServer ){
// create an object url
// Matt actually uses this line when he creates Recorder.forceDownload()
var url = (window.URL || window.webkitURL).createObjectURL(blob);
// create a new request and send it via the objectUrl
var request = new XMLHttpRequest();
request.open("GET", url, true);
request.responseType = "blob";
request.onload = function(){
// send the blob somewhere else or handle it here
// use request.response
}
request.send();
}
}
// very important! run the following exportWAV method to trigger the callback
rec.exportWAV();
让我知道这是否有效.. 尚未测试但它应该有效。干杯!
关于ajax - RecorderJS 通过 AJAX 上传记录的 blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15014638/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!