Comparison between instanceof and constructor.name

Background information:
Currently, our application retrieves images from a GET API

Accept: 'application/octet-stream',
responseType: 'blob'

and we utilize the following method to display the image on the user interface.

let imageUrl = URL.createObjectURL(data);

Although this process works smoothly in most cases on Chrome (both Windows and MAC), it encounters an error response in Safari at one specific location.

"Response is not a Blob."

Upon investigation, we discovered that Angular is throwing this error.

case 'blob':
return res$.pipe(map((res) => {
    // Validate that the body is a Blob.
    if (res.body !== null && !(res.body instanceof Blob)) {
        throw new Error('Response is not a Blob.');
    }
    return res.body;
}));

When inspecting the

res.body instanceof Blob // true in chrome but false in safari

I proceeded to further investigate in Safari

res.body.constuctor.name where I received a response like "Blob"

This leads me to ask,

How can I determine the output of the instanceof value?

Answer №1

Consider using this alternative

fetch(url)
  .then(response => response.blob())
  .then(blob => URL.createObjectURL(blob));

The crucial aspect is setting responseType: 'blob'. Inconsistent behavior may occur on Safari or iOS browsers, so utilizing this method ensures compatibility across all platforms. This scheme is recommended solely for managing image content.

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

How can I trigger a row click event while a TextInput is in focus? (react-native)

Whenever I tap on a ListView item, the TouchableOpacity functions properly. However, when a TextInput is in focus, it requires two taps for it to work - the first tap only removes the focus from the TextInput. Is there a way to make it work without havin ...

How can one check in JavaScript if a specific URL was targeted with a XMLHttpRequest?

While I am familiar with monitoring network traffic in the browser's development tools and having XMLHttpRequests shown in the console, I am curious if there is a specific window property that showcases all network activity at once? ...

Using styled-components to enhance an existing component by adding a new prop for customization of styles

I am currently using styled-components to customize the styling of an existing component, specifically ToggleButton from material ui. However, I want my new component to include an additional property (hasMargin) that will control the style: import {Toggle ...

What is the best way to initiate a function from within another function while working with ReactJS?

Seeking guidance on how to trigger a Redux state change by calling a function from another function using the onClick event. Currently, I am able to invoke the Jammingmenu upon clicking an icon, however, no action is performed or alert displayed. Any assis ...

The pie chart fails to fully display

Check out the repro example I made here. The legend is displaying properly, but the graph is not showing up. What could be causing this unexpected issue? ...

Exploring JavaScript-based navigation with Python and Selenium

Here is the URL of the page in question: link. I am trying to navigate pagination with the following HTML markup: <li class="btn-next"> <a href="javascript:ctrl.set_pageReload(2)">Next</a></li> I have written a ...

How to Override package.json Scripts in NPM

Is it possible to modify package.json scripts without changing the original file? I need to customize the memory allocation for a specific step, but altering the package.json will affect everyone. For example, our current script is: "script": { "dev": ...

Make toggleClass show up smoothly without disappearing

I'm currently working with jQuery's toggleClass() method and I want to achieve a fade-in effect without the corresponding fade-out animation. Using the "duration" attribute applies the same duration for both actions, which is not what I want. I w ...

AngularJS experiencing issues with Bootstrap multiselect functionality

I am currently integrating bootstrap-multiselect into my AngularJS application. To do this, I've included the following scripts in my master page (index.html). <script src="/bower_components/jquery/dist/jquery.min.js"></script> <scrip ...

While trying to update Angular 5 to 6, I am encountering an incompatible peer dependency error when utilizing the ng update @angular/core command

I have been encountering issues while trying to upgrade my Angular app from version 5 to version 6 by following this guide. After successfully running the commands below: npm install -g @angular/cli npm install @angular/cli ng update @angular/cli An err ...

Tips for incorporating Electron into an Angular 5 project

I've been attempting to incorporate electron into my app for invoice printing using: import { BrowserWindow } from 'electron' However, an error is being thrown, stating: fs.existsSync is not a function I also tried requiring it from th ...

"Encountering issue with auto-import suggestions failing to appear in VS Code version 1.88.0

After installing the necessary libraries for MUI, I encountered an issue where basic components like Typography were not showing up in intellisense. Instead, it was displaying @mui/icons-material. You can view screenshots below: https://i.stack.imgur.com/ ...

The HTTP request is being executed twice for some reason unknown to me

import React, {useState, useEffect} from 'react' export function UseStateExample() { // This is a named export that must be used consistently with {} when importing/exporting. const [resourceType, setResourceType] = useState(null) useEffect ...

Obtaining a subset of data from firebase

I am currently working on retrieving a sub-collection from the Firestore database using Angular. In my database, I have a collection called 'Company' which contains fields for 'Name' and 'Id', as well as a sub-collection named ...

Using CORS with Spring Boot and React Admin in React applications

For the admin interface, I am utilizing a tool called "React Admin" along with Spring Boot for my REST API. The React app's URL is: "http://localhost:3000", while the Spring Boot API's URL is: "http://localhost:8080". In my project, I have a sep ...

When the dialog is opened, automatically set the focus on the text field inside

I am facing an issue with focusing a custom text field when opening a dialog. I have tried using vue.js refs: Code: <v-app id="app"> <v-row align="center"> <v-col class="text-center" cols="12"> <v-btn color="primary" @cli ...

After closing, remove the #about section from the URL

One of the buttons on my webpage triggers an overlay using JavaScript that directs to a URL like the following: However, when the close button is clicked, the overlay is removed but the "/#about" part of the URL remains. What is the most effective method ...

After restarting, Nuxt 3 runtime configuration values do not get updated with environment variables

Encountered a challenge with updating variables in runtimeConfig that rely on environment variables. When the application is built with values from the .env file like: API_URL=localhost:3000 The console displays localhost:3000. However, upon stopping th ...

Trouble arises when implementing MultiLineString functionality within LeafletGIS

After receiving a response from the server, I found that I needed to restructure it to fit the GeoJSON standard in order to use it for marker animation in Leaflet. The coordinates also needed to be flipped, as Leaflet uses lat, lng while my data was in lng ...

Which tool is best suited for generating a diagram within an Angular application?

I am looking to create a project diagram with drag and drop functionality, allowing users to add nodes. I am interested in incorporating a feature similar to the image provided below using Angular9. Can anyone recommend an npm package that is compatible wi ...