Error encountered when attempting to load image from URL in domain

Why won't the image load on my domain?

The image loads fine on other domains, but not mine

Is there a problem with my domain?

var textureLoader = new THREE.TextureLoader();
textureLoader.crossOrigin = '';
var map = textureLoader.load('https://MY-DOMAIN.com/upload/01.png');

Error : GET net::ERR_FAILED

Note : I'm working on localhost. I taking pictures from remote server

Answer №1

Upon analyzing the response header sent by your server, it seems that the Access-Control-Allow-Origin header is missing. It should ideally either be set to <origin> or *.

If you are using LiteSpeed Web Server, I recommend checking out their Wiki page for guidance:

When attempting to access your image through a proxy, everything appears to function correctly.

var textureLoader = new THREE.TextureLoader();
textureLoader.crossOrigin = '';
var map = textureLoader.load('https://api.codetabs.com/v1/proxy?quest=https://zomisoft.com/blog_img/5-5bcf0cae447c36.35706243.png');

Answer №2

Alternative approach I discovered

Retrieving image in base64 format using a web service

Utilizing a web service

<?php

header("access-control-allow-origin: *");


if($_GET['key']=='1453'){
    try {
$path  = $_GET['url'];

$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);

    echo $base64;
    } catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
    }
}else{
    echo 404;
}

Implementation with three.js

var image = new Image();
image.src = data;//base64 type image from web service

var texture = new THREE.Texture();
texture.image = image;

image.onload = function() {
  texture.needsUpdate = true;
};

var material = new THREE.MeshPhongMaterial({
  map: texture,
});

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

Utilizing loop variables in ng-class and ng-click directive

This piece of code generates a list consisting of seven thumbnails, with the currently active image designated by the active and thumb classes. <div ng-repeat="no in [1, 2, 3, 4, 5, 6, 7]"> <img ng-src="images/{{no}}t.jpg" class="thumb" ng ...

What is the method to track the movement of the mouse in the reverse direction?

I am looking to create a unique div that moves in the opposite direction of the mouse cursor within another div called .box. As the mouse moves, I want the red box to create a subtle parallax effect by slightly moving in the opposite direction. Instead of ...

What is the best way to generate a random string output from an object in JavaScript?

I'm struggling with extracting a random value from the object provided below, can anyone help me out? const hellos = { English: "Hello", Japanese: "Konnichiwa", German: "Hallo", Spanish: "Hola", Arabic: "Ah ...

Aligning intersected objects to always face the camera in A-Frame through rotation

When I create objects by clicking, their position is defined but the rotation doesn't update when the camera moves. I attempted to use the `lookAt` package to make them face the camera, but it didn't work. This is my first time using a-frame, and ...

Discovering how to locate a div element in one component from a separate component using Vue.js

Imagine having multiple Vue.js components in one project. <loginFields></loginFields> <submitButton></submitButton> Now, when the submitButton (which is a div with a unique id) is clicked, I want to initiate a method that checks t ...

How can I update the value of a span element that was added to the HTML document through an AJAX request?

When a modal is triggered on click, data is added to it through an AJAX request to a PHP file. After the AJAX call, I want the values in span elements within the modal to change simultaneously with the input field of the modal. I attempted this JavaScript ...

MongoDB failing to store model information

As I dive into practicing with APIs to hone my skills in creating models and routes, I find myself stuck on getting my initial route to successfully save data to my MongoDB database. When testing with Postman, I encounter the following error: { "message" ...

Animating a child element while still keeping it within its parent's bounds

I have researched extensively for a solution and it seems that using position: relative; should resolve my issue. However, this method does not seem to work in my specific case. I am utilizing JQuery and AnimeJS. My goal is to achieve the Google ripple eff ...

Replace or update the current array of objects that align with the incoming array

I've been struggling to figure out how to find and replace an array that matches the existing one. The issue lies with using the some method. Here is the current array: let existingData = [{ id: 1, product: 'Soap', price: ' ...

Changes made to the data are not reflected in the user interface, but they are visible in the console

When working on a React project with input fields, I encountered an issue where the date data can be changed but doesn't get reflected in the UI. Instead, the updated data is visible in the console. The code snippet below showcases how I'm using ...

What are the solutions for addressing object flickering when planes share the same z value in ThreeJS?

I want to make sure that later drawn object blocks are displayed in front of previously drawn objects if they have the same z value, similar to z-index in CSS. How can I achieve this effect? There is a constant called "CullFaceFrontBack" which can be foun ...

What is a more dynamic way to assign attributes to elements without directly embedding them in the HTML code?

For my unique scenario, my goal is to assign the attribute target = "_blank" to all <a> elements within a specific div in order to open them in new tabs. This concept could potentially be applied to any element and any attribute. I am curious if the ...

Cannot retrieve Global variables when using chrome.tabs.executescript in Chrome 55

After recently updating Chrome to version 55.0.2883.75, I encountered an issue with my self-developed Chrome Plugin used for parsing HTML files. In the plugin, I utilize chrome.tabs.executescript to retrieve data from a background HTML page. Previously, I ...

Challenges with Vuex and updating arrays using axios

I am currently facing a challenge with VueJS Vuex and Axios: The issue arises when I retrieve an array with Axios and loop through it to populate its children this way: "Rubriques" has many self-relations, so one rubrique can have multiple child rubriques ...

Stopping Angular Route Alteration Depending on Routing Conditions

I have been searching everywhere for a solution to this issue. My goal is to be able to access the routing parameters collection and prevent the route from loading if a certain parameter is missing. I have tried using preventDefault in $routeChangeStart, b ...

Implementing a for loop within a scrolling function

How do I multiply functions inside the scroll loop? This is what I currently have: $(window).scroll(function() { b1Center = $("#block-1").offset().top - ($(window).height() - divHeight) / 2; b1Bottom = $("#block-1").offset().top - $(window).height(); b1T ...

Limit the input to a specific format

Currently developing a JavaScript application, but having some confusion with Regular Expressions. The main goal is to allow users to input a specific format of strings in a text area for the application to process accordingly, thus requiring restriction o ...

What purpose does the symbol '$' serve in React component properties?

While delving into the world of styled-component, I encountered some difficulties with the 'adapting based on props' aspect. import './App.css'; import styled from 'styled-components' const PrimaryButton = styled.button` co ...

Access the latest data within Sails' Waterline prior to the update process

When using Sails' Waterline, I am tasked with comparing the previous value to the new one and assigning a new attribute based on certain conditions. For instance: beforeUpdate: function(newValues, callback) { if(/* currentValues */.age > newVal ...

retrieve particular content from html following ajax return

Currently, I am in the process of working on ajax functionality where I need to send a request to retrieve data from a specific page. The challenge that I am facing is that the target page contains a complete template with a header, footer, side menu, and ...