Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在客户端javascript中将.wav文件从url转换为base64?_Javascript_Base64_Blob_Wav - Fatal编程技术网

如何在客户端javascript中将.wav文件从url转换为base64?

如何在客户端javascript中将.wav文件从url转换为base64?,javascript,base64,blob,wav,Javascript,Base64,Blob,Wav,我有.wav文件,放在“”上。如何在客户端javascript上使用base64编码获取它 getFile('http://yy.zz/1.wav', (file) => { console.log(getBase64File(file)); // profit }); 如果文件位于同一域中,或者您在外部站点上启用了CORS,则可以执行以下操作: $.get("http://localhost/content/sound/hello.wav", function(file){

我有.wav文件,放在“”上。如何在客户端javascript上使用base64编码获取它

getFile('http://yy.zz/1.wav', (file) => {
  console.log(getBase64File(file)); // profit
});

如果文件位于同一域中,或者您在外部站点上启用了CORS,则可以执行以下操作:

$.get("http://localhost/content/sound/hello.wav", function(file){
   let fileInBase64Format = btoa(unescape(encodeURIComponent(file)));
   console.log(fileInBase64Format);
});