I tried pulling an image from a MySQL server and it is always returning an error. I have tried for hours to find work arounds for Content Security Policies but I cant figure out this one. Now the image frames get loaded but the image would not be set. Here is my code.
inputImages.php
<?php
$server_name = "localhost";
$my_user = ""; //taken out for stackoverflow question
$my_passcode = ""; //taken out for stackoverflow question
$db_name = ""; //taken out for stackoverflow question
$conn = mysqli_connect($server_name, $my_user, $my_passcode, $db_name);
if (!$conn)
{
die("Could not connect");
}
else //Hopefully this runs instead
{
try
{
$sql_query = mysqli_query($conn, "SELECT * FROM `adDatabase`");
while ($row = mysqli_fetch_array($sql_query))
{
$id = $row['ID'];
$img = $row['img'];
$image = '<img src="data:image/png;base64,'.base64_encode( $row['img'] ).'" style="height: 12em; width: 12em" >';
echo $image;
}
}
catch(Exception $e)
{
echo $e;
}
}
?>
And the js file with ajax request
window.onload = function()
{
$.ajax({
url: '', //taken out for stackoverflow question
success: function(data)
{
$(".latest-ads").html(data);
}
});
}
But nothing loads and I get this error
jquery.js:5873 Refused to load the image 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkAAAAHkCAYAAADW/5BTAAAYK2lDQ…FCoBAoBAqBQqAQOFIEarf3kTZcsV0IFAKFQCFQCBQCN0fg//rs0Cqe5CYQAAAAAElFTkSuQmCC' because it violates the following Content Security Policy directive: "default-src *". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.
I am NOT trying to load a script. I am trying to load an image but the image is not rendering or being read.
EDIT - material requested within the comments - manifest.json
{
"manifest_version": 2,
"name": "Smart Lead Advertisment",
"version": "1.0",
"description": "Smart Lead Advertisment, helping you advertise in a more effecient way.",
"author": "Smart Lead Advertisment",
"browser_action": {
"default_popup": "html/popup.html",
"default_title": "Click here"
},
"content_scripts": [
{
"matches": ["http://*/", "https://*/", "file:///*/"],
"js": ["js/jquery.js", "js/bootstrap.min.js", "js/ad-injection.js"]
}
]
}
Try returning the
base64string fromphp, creating<img>element atsuccessof$.ajax(), settingsrcof<img>todata URIrepresentation ofbase64string