typescript - How to post and bind images that coming as BASE64 string from the server in Angular 2 -


i want send uploaded files base64 can pass request(i using remote api's). problem i'm using angular 2 typescript , couldn't find info on how that. found in javascript can done canvas .i have created javascript function convert image base64 , file using

  //insted of ng-model in case of file upload            var imgedata = event.srcelement.files;            console.log(imgedata); 

so index. html contains

    <script type='text/javascript'>        function encodeimagefileasurl() {            // logic convert base64             //ng-model file            var imgedata = event.srcelement.files;            console.log(imgedata);        }        </script> 

html like

              <input id="inputfiletoload" type="file"                           onchange="encodeimagefileasurl(); " /> 

here after selecting image getting file name , details in

        var imgedata = event.srcelement.files; 

the real confusion coming here after in "imagedata" ive image(file) details.how can send along other json data?

my save methode

          //in service.ts              savedetails(mar: model) {      let body = json.stringify([         {             "id": 0,             "name": mar.name,             "age": mar.age,             "imageurl": mar.imageurl,              "imgedata": "how can pass imagedata in                 javascriptfunction along these details???                               "              "updatedby": "admin",             "updatedon": "2017-07-05"          }     ]);     console.log(body);     let headers = new headers({         'content-type':         'application/json; charset=utf-8'     });     let options = new requestoptions({ headers: headers });     return this._http.post(this.serverurl , body, options)         .map(res => <model[]>res.json())         .catch(this.handleerror); } 

so file details getting js function, send along details how can send?

same need bind converted base64 images.how can bind ?

for binding ve tried

      <img src="data:image/gif;base64,{{ m.imgedata}}"> 

unfortunatly s not working.. me find solution bind/save file

thanks.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -