Click here to Skip to main content
16,020,447 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
convert base64 string into byte array and save in mp3 file format
Posted
Updated 28-Feb-18 21:28pm

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

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


If it isn't, then it will look like an MP3 until an app tries to open it, when it will fail to play.
 
Share this answer
 
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);
            });
        });
    });
}
 
Share this answer
 
Comments
[no name] 1-Mar-18 3:53am    
Already solved, this is not C#, and SIX years too late.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900