Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #35238

Array of Files to array of data url

Newsgroups comp.lang.javascript
From Andrew Poulos <ap_prog@hotmail.com>
Subject Array of Files to array of data url
Date 2018-06-19 19:44 +1000
Message-ID <8dGdnZA1WKvpTbXGnZ2dnUU7-e3NnZ2d@westnet.com.au> (permalink)

Show all headers | View raw


I have this array

var files = [File, File, null, File];

and I need to create a new array with the data from each File (or null 
if it's null).

I tried

var newarr = files.map(function(el){
   if (el === null) return null;

   var reader = new FileReader();

   reader.addEventListener("load", function () {
     return reader.result;
   }, false);

   reader.readAsDataURL(el);
});

but the array only ever gets populated with null. How can this be done?

Andrew Poulos

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Array of Files to array of data url Andrew Poulos <ap_prog@hotmail.com> - 2018-06-19 19:44 +1000
  Re: Array of Files to array of data url Jake Jarvis <pig_in_shoes@yahoo.com> - 2018-06-19 12:28 +0200
  Re: Array of Files to array of data url Jon Ribbens <jon+usenet@unequivocal.eu> - 2018-06-19 14:47 +0000
  Re: Array of Files to array of data url Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-06-20 21:47 +0200
    Re: Array of Files to array of data url Andrew Poulos <ap_prog@hotmail.com> - 2018-06-21 15:33 +1000
  Re: Array of Files to array of data url "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-06-21 15:16 -0700

csiph-web