Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!