Accessing image from Azure with the assistance of Graph API

I need assistance with retrieving a profile picture using the Microsoft Azure API. The code snippet provided below demonstrates my attempt to do so.

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 });
    // Retrieve the photo from the 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);
    });
}

However, I am facing an issue where the output I receive is:

data:image/bmp;base64,W29iamVjdCBCbG9iXQ==

Which appears as [object Blob].

My inquiry pertains to how I can obtain the image object in this scenario?

Answer №1

When using PHP, the process is much simpler compared to nodejs. In nodejs, you need to include this code within a function that takes req as a parameter:

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);
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Extracting regular expressions between the penultimate and ultimate characters

I'm struggling with a simple regex question. I want to extract text between two specific characters: - and ~ Here's my string: Champions tour - To Win1 - To Win2 ~JIM FURYK Currently, when I use this regex pattern: \-([^)]+\~), it mat ...

Will the script src onclick change have an effect after the page is fully loaded?

Imagine you have a script that loads right away when a page loads. Now, what happens if the script src changes when you click on a button? Will the new src get executed? Here is some example code: <button> click </button> <script class=" ...

Ajax is malfunctioning and failing to fulfill my needs

I cannot get Ajax to submit no matter what. I've been struggling for hours... script: <script> $(document).ready( $("#submit").click(function(e) { e.preventDefault(); $.ajax({ url: "https://maps.googleapis.com/maps/ ...

Creating a function that writes to a file by utilizing the data input from

After running the provided code snippet, it successfully works in a standalone project. However, I am interested in making modifications to replace the variable "sample_text" with an output that is displayed in the terminal instead of being hardcoded int ...

If the user is not authenticated, Node.js will redirect them to the login page

I've integrated the node-login module for user login on my website. Once a user logs in, the dashboard.html page is rendered: app.get('/', function(req, res){ // Check if the user's credentials are stored in a cookie // if (req.coo ...

sophisticated HTML navigation bar

I am looking for a way to create a menu where the drop-down items overlay the rest of the menu when the screen width is small. Here is my current code: nav{ line-height:100%; opacity:.9; }nav ul{ background: #999; padding: 0px; border-radius: 20px; ...

Error encountered in Angular Html2Pdf: Unable to assign the 'adoptedStyleSheets' attribute on 'ShadowRoot' due to DOMException

Looking for assistance in implementing html2pdf with Angular 12 to convert specific parts of an HTML page into a downloadable PDF. ERROR MESSAGE An error occurred while trying to execute the code: index-7a8b7a1c.js:150 Uncaught (in promise) DOMExce ...

Creating Structure with Highcharts - Sorting Through Unprocessed Data

In reviewing various demos of highcharts, I noticed that they all tend to adhere to a fairly straightforward data structure: Categories,Apples,Pears,Oranges,Bananas John,8,4,6,5 Jane,3,4,2,3 Joe,86,76,79,77 Janet,3,16,13,15 However, the data I have doesn ...

Pass an array from JavaScript to PHP

I am attempting to send an array to the server using jQuery. Here is my code snippet for sending the array: jQuery(document).ready(function($){ $.ajax({ type: "POST", url: "file.php", datatype : "json", data : JSON.str ...

Redirecting in AngularJS after a successful login操作

Is there a way to redirect users back to the original page after they login? For example, if a user is on a post like www.example.com/post/435 and needs to log in to "like/comment" on the post, how can I automatically redirect them back to that specific po ...

Executing end-to-end tests on Sauce Labs using Protractor with Travis

I am currently working on my open source project which can be found at https://github.com/ahmednuaman/radian. I have implemented some e2e tests that are running smoothly on my local setup using Protractor. I followed the documentation provided by Sauce La ...

The functionality of the dynamic drag and drop form builder is not functioning as expected in Angular 12

I am currently developing a dynamic form builder using Angular version 12. To achieve this, I decided to utilize the Angular-Formio package. After installing the package and following the steps outlined in the documentation, I encountered an issue. The i ...

`Jump-start Your Development with jQuery Lightbox Centering`

Recently, I implemented a lightbox effect for images on my website. However, I encountered an issue where the lightbox was not centering properly in the window upon initial click. Instead, the lightbox would appear at the bottom of the page on the first cl ...

Unable to locate the inner text of a Div element using ElementRef in Angular 9

I'm facing an issue with my code where I am trying to find the innerText of a div and change it. However, when I click on the button to retrieve the innerText, it shows as undefined. Check out the demo here <p #dviInner> Start editing to se ...

Error: The function $rootScope.$on is not defined within the Connectivity Factory

I am facing an issue with my Ionic app while trying to run it in offline mode. The error message "services.js:392 Uncaught TypeError: $rootScope.$on is not a function" appears when I launch the app. Can someone please explain why this is happening and what ...

Tips for attaching a React hook to a DOM element generated using a jQuery function

I have a project written in jQuery that I am looking to integrate into my React project. My goal is to send a query to my graphql server when a button is clicked. Within my jQuery code, there is a function that creates multiple elements as shown below: c ...

Arranging based on attribute data

I'm currently working on organizing a collection of divs that have unique custom data attributes which I aim to sort based on user selection. For instance, if 'followers' is chosen, the .box elements will be arranged according to their data- ...

Locate every instance of items in an array within a string

My files have a structure similar to this: https://i.stack.imgur.com/KyaVY.png When a user conducts a search, they send an array to the backend. This array always includes at least one element. For example, if they send ['javascript'] to the b ...

Checking the validity of a JSON file extension using regular expressions

Using EXTJS, I have created a file upload component for uploading files from computer. I need to restrict the uploads to JSON files only and want to display an error for any other file types. Currently, I am able to capture the filename of the imported fil ...

Displaying the identical date on two separate Ajax Calendar Extender controls in Asp.net

I am facing an issue with some ajax calendar extenders. I have two similar calendars and two textboxes, each linked to one calendar. <asp:TextBox ID="txt1" runat="server"</asp:TextBox> <cc1:CalendarE ...