Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encode base 64 to .kml file?

I convert kml file to base 64. Now I want to encode base 64 to become kml file again? is this possible? I convert kml file like this..

        $scope.myFunction = function () {
        var files = document.getElementById('myFile').files;
        if (files.length > 0) {
            getBase64(files[0]);
        }
    }

    function getBase64(file) {
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () {
            console.log(reader.result);
        };
        reader.onerror = function (error) {
            console.log('Error: ', error);
        };
    }

how can I store kml file to database?

like image 310
Yamoshi Wolverine Avatar asked Jan 31 '26 05:01

Yamoshi Wolverine


1 Answers

It surely is possible, you just have to decode the base64 and turn the result into a file again.

function base64ToFile(base64){

  content=atob(base64);
  var file = new Blob([content], {type: 'kml'});

  //You can now asign the file to a link to download, send it with ajax, etc..

  a.href = URL.createObjectURL(file);

}

Bear in mind, that you cant write a file directly onto disk from javascript, because that would be a security issue, you need t

like image 82
Ernesto Mayoral Cabezas Avatar answered Feb 01 '26 19:02

Ernesto Mayoral Cabezas