Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
Display image from S3 by getting URL of the image from mysql database

I have a dynamic web project and in this one I try to display elements from a mysql database on an AWS Instance. So, in my database, I have many elements (name, city, imageURL) and the imageURL is an URL from an image in an amazon S3.

In my html code, if I put the URL directly, the image is displayed but if I get back the URL from the mysql database (with a javascript function), I got the right url with console.log(imageURL) but the image is not displayed and I have this error :

GET https://s3-us-west-2.amazonaws.com/.... 403 (Forbidden)

So do you know why this doesn't work ?

EDIT : This is my javascript code :

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
    myFunction(this);
}
};
xhttp.open("GET", "rest/restaurants", true);
xhttp.send();

function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var name;
    var id;
    var imageURL;
    var htmlText = "";

for (i = 0; i< xmlDoc.getElementsByTagName("id").length; i++){
    name = xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue;
    id = xmlDoc.getElementsByTagName("id")[i].childNodes[0].nodeValue;
    imageURL = xmlDoc.getElementsByTagName("imageURL")[i].childNodes[0].nodeValue;

    console.log(imageURL);

        htmlText = htmlText + 
        "<div class=\"Popular-Restaurants-grid\">" +
        "<div class=\"col-md-3 restaurent-logo\">" +
        "<img src="+ imageURL + "class=\"img-responsive\"/>"+
        "</div>"+
        "<div class=\"col-md-2 restaurent-title\">"+
        "<div class=\"logo-title\">"+
        "<h4 id=\"test\"><a href=\"#\">" + name + "</a></h4>"+
        "</div>"+
        "</div>"    
        }
    document.getElementById("restaurantsContainer").innerHTML = htmlText;
}
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Your current code generates a URL like:

<img src=https://s3-us-west-2.amazonaws.com/someText/text/logo1.jpgclass="img-responsive"/>

Add a space to this line:

"<img src="+ imageURL + "class=\"img-responsive\"/>"

to look like:

"<img src="+ imageURL + " class=\"img-responsive\"/>"

Notice the space before the word "class".

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda