简体   繁体   English

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

[英]how can i convert .wav file from url to base64 in client-side javascript?

I have .wav file, placed on " http://yy.zz/1.wav ".我有 .wav 文件,放在“ http://yy.zz/1.wav ”上。 How can i fetch it with base64 encoding on client-side javascript?如何在客户端 javascript 上使用 base64 编码获取它?

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

If the file is on the same domain or you have CORS enabled on the external site, you can do the following:如果文件在同一个域中,或者您在外部站点上启用了 CORS,您可以执行以下操作:

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

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

相关问题 如何使用 Cloudinary 客户端将 Blob URL 转换为 Base64 字符串并检索图像 URL? - How to convert Blob URL to Base64 string and retrieve an Image URL using Cloudinary Client-Side? 客户端 Javascript 中的 Base64 编码和解码 - Base64 encoding and decoding in client-side Javascript 我可以将图像从base64转换为二进制客户端吗? - Can I convert an image FROM base64 to binary client side? 使用multer从客户端获取详细信息后,如何在nodejs中以base64编码文件 - How to encoded files in base64 in nodejs after getting details from client-side using multer 客户端JS传递base64编码文件到服务端JS进行API调用 - Pass base64 encoded file from client-side JS to server-side JS to make API call 如何将.wav响应转换为Blob网址,以便我可以使用JavaScript在客户端播放音频 - How to convert .wav response in to blob url so that I can play as audio in client side using javascript 如何在JavaScript中将文件转换为base64? - How to convert file to base64 in JavaScript? 如何在 React-Native 中将 base64 url 转换为图像(png/jpg)文件? - How can I convert a base64 url to an image(png/jpg) file, in React-Native? 如何在客户端将下载的嵌入式图像转换为Base64 - How convert downloaded inline image into Base64 on client side 如何将Base64图像转换为文件类型 - How can I convert Base64 image to file type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM