将base64字符串转换为字节数组并以mp3文件格式保存 [英] convert base64 string into byte array and save in mp3 file format

查看:272
本文介绍了将base64字符串转换为字节数组并以mp3文件格式保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将base64字符串转换为字节数组并保存为mp3文件格式

convert base64 string into byte array and save in mp3 file format

推荐答案

假设Base64字符串是一个MP3文件,您只需要Convert.FromBase64String方法 [ ^ ]



Assuming the Base64 string is an MP3 file, all you need is the Convert.FromBase64String Method[^]

byte[] bytes = System.Convert.FromBase64String(stringInBase64);
File.WriteAllBytes(@"D:\Temp\myFile.mp3", bytes);





如果不是,那么它会看起来像一个MP3,直到一个应用程序试图打开它,它什么时候会无法播放。



If it isn't, then it will look like an MP3 until an app tries to open it, when it will fail to play.


function saveBase64AsAudioFile(folderpath,filename,content,contentType){
    // Convert the base64 string in a Blob
    var DataBlob = b64toBlob(content,contentType);

    console.log("Starting to write the file :3");

    window.resolveLocalFileSystemURL(folderpath, function(dir) {
        console.log("Access to the directory granted succesfully");
        dir.getFile(filename, {create:true}, function(file) {
            console.log("File created succesfully.");
            file.createWriter(function(fileWriter) {
                console.log("Writing content to file");
                fileWriter.write(DataBlob);
            }, function(){
                alert('Unable to save file in path '+ folderpath);
            });
        });
    });
}


这篇关于将base64字符串转换为字节数组并以mp3文件格式保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆