Asp.Net, C#, Java Script, Jquery, Web

Convert base64 string into file using Java script


Here you find java script code convert base64 string to file. I converted excel file to base64 string to demo example. I did it in c# code.

Code to convert file into Base64

using System;
using System.IO;
using System.Linq;

namespace Demo
{
public class Program
{
public static void Main(string[] args)
{
var fileBytes = File.ReadAllBytes(@”d:\temp.xlsx”);

string encodedFile = Convert.ToBase64String(fileBytes);

Console.WriteLine(“Base 64 Encoded File : {0}”, encodedFile);

var decodedFileBytes = Convert.FromBase64String(encodedFile);

File.AppendAllText(“d:\\temp.txt”,encodedFile);

File.WriteAllBytes(@”d:\newtempfile.xlsx”, decodedFileBytes);
}
}
}

You can expose file upload or download via service where file can be transferred as base64 string.
Java script code to consume base64 string and download as file:

 

function convertBase64ToExcel()
{

var data = “UEsDBBQABgAIAAAAIQBi7p1oXgEAAJAEAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AgAAsQUAAA0AAAAAAAAAAAAAAAAAUBIAAHhsL3N0eWxlcy54bWxQSwECLQAUAAYACAAAACEAChQRqw8CAAA3BQAAGAAAAAAAAAAAAAAAAAABFQAAeGwvd29ya3NoZWV0cy9zaGVldDEueG1sUEsBAi0AFAAGAAgAAAAhAJbKnjo+AQAAUQIAABEAAAAAAAAAAAAAAAAARhcAAGRvY1Byb3BzL2NvcmUueG1sUEsBAi0AFAAGAAgAAAAhAN5BFtmKAQAAEQMAABAAAAAAAAAAAAAAAAAAuxkAAGRvY1Byb3BzL2FwcC54bWxQSwUGAAAAAAoACgCAAgAAexwAAAAA”;

var contentType = ‘application/vnd.ms-excel’;
var blob1 = b64toBlob(data, contentType);
var blobUrl1 = URL.createObjectURL(blob1);

window.open(blobUrl1);

}

function b64toBlob(b64Data, contentType, sliceSize) {
contentType = contentType || ”;
sliceSize = sliceSize || 512;

var byteCharacters = atob(b64Data);
var byteArrays = [];

for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);

var byteNumbers = new Array(slice.length);
for (var i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}

var byteArray = new Uint8Array(byteNumbers);

byteArrays.push(byteArray);
}

var blob = new Blob(byteArrays, {type: contentType});
return blob;
}

You can find running code here: Jsfiddle

//jsfiddle.net/neerajkaushik_123/s9g9nqa1/6/embedded/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s