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


Groups > comp.lang.javascript > #35239

Re: Array of Files to array of data url

From Jake Jarvis <pig_in_shoes@yahoo.com>
Newsgroups comp.lang.javascript
Subject Re: Array of Files to array of data url
Date 2018-06-19 12:28 +0200
Organization A noiseless patient Spider
Message-ID <pgalt3$hdf$1@dont-email.me> (permalink)
References <8dGdnZA1WKvpTbXGnZ2dnUU7-e3NnZ2d@westnet.com.au>

Show all headers | View raw


Am 19.06.2018 um 11:44 schrieb Andrew Poulos:
> 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

File API is asynchronous. ("Don't call us, we'll call you")

No idea what the big picture is, maybe those new Promise things can help.

Back to comp.lang.javascript | Previous | Next — Previous in thread | 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