1

In Javascript, test browser is Firefox. I have converted files to an array of bytes to store on my server and have used the subsequent code to convert the bytes back to a file, but I am unsure as to how to download the newly created file with appropriate file type can anyone please direct me?

to blob

$('input[type="file"]').change(function(e){

  function convertFile(file){
      return Array.prototype.map.call(new Uint8Array(file), x => ('00' + x.toString(16)).slice(-2)).join('');
  }
    file = event.target.files[0];
    fileName = file.name;
    fileSplit = fileName.split('.');
    last = fileSplit.length-1;
    let fileType = fileSplit[last];

    $('#FileNameVisible').text(fileName);
    var reader = new FileReader();
    reader.readAsArrayBuffer(file);
    reader.onload = function(e) {
      fileData = e.target.result;
      fileData = convertFile(e.target.result);
      console.log(fileData);
        };
      reader.onerror = function() {
          console.log(reader.error);
      };
  });

from Blob

var file = new File([dataUse], "File", {lastModified: Date.now()});

console.log(file);
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • 1
    https://stackoverflow.com/questions/19327749/javascript-blob-filename-without-link look to this post :) – zyad osseyran Jul 12 '20 at 16:45
  • The save functionality is exactly what I was looking for and I was testing it out but even when I change the type to the correct one (image/png in this case) and try to open them it tells me that photos is unable to view this file which is what I used to check it initially – WesternWarrior Jul 12 '20 at 17:21

0 Answers0