2017-10-23 1 views
0

Ich versuche, ein Profilbild von der Microsoft Azure-API abzurufen. Der folgende Code zeigt, wie.Abrufen von Foto aus Azure mit Graph API

private getProfilePicture(bearerToken: string, tenantId: string): void { 
    let command = CommandHelper.createRestBlobCommand([ 
     { name: 'https://graph.microsoft.com/beta'}, 
     { name: 'me/photo/$value' } 
    ]); 

    command.Headers.push({ name: 'Authorization', value: 'bearer ' + bearerToken }); 
    // load the photo from graph api. 
    this._gateway.send(command).subscribe(result => { 

     let info = result.payload; 

     var Base64 = require('js-base64').Base64; 
     var temp = 'data:image/bmp;base64,' + Base64.encode('info'); 
     console.log(temp); 

     let action = actions.AuthenticationActions.photoLoaded(info); 

     this._store.dispatch(action); 
    }); 
} 

Das Problem ist jedoch, dass, wenn ich am Ausgang schauen sie zurück:

data:image/bmp;base64,W29iamVjdCBCbG9iXQ== 

die auf [Objekt Blob] übersetzt.

Meine Frage ist, wie Sie das Bildobjekt hier bekommen?

+0

dies ist die Bildquelle ohne Stelle. Wenn Sie das Objekt rechts klicken und speichern möchten als ... –

+0

headmax, wie sollte das im Code getan werden? –

Antwort

0

mit PHP ist sehr einfach in NodeJS Sie diese an die Funktion zu setzen haben, die req als param zurückkehren und tun es wie folgt aus:

app.get('/...', function(req, res){ ... 

var base64Data = req.rawBody.replace(/^data:image\/bmp;base64,/, ""); 

require("fs").writeFile("out.bmp", base64Data, 'base64', function(err) { 
    console.log(err); 
}); 
Verwandte Themen