I am trying to load images from in my react component but I am getting this error Refused to load the image 'blob:https://canister_id.icp0.io/76684b08-27e4-4c3f-b260-16847c3b7df6' because it violates the following Content Security Policy directive: "img-src 'self' data:".
.
I tried fixing the problem by updating the metadata to this:
<meta
http-equiv="Content-Security-Policy"
content="default-src *;
img-src * 'self' data: https: blob:; script-src 'self' 'unsafe-inline' 'unsafe-eval' *;
style-src 'self' 'unsafe-inline' *"
/>
But the error still ramained as above.
I should also add that the react frontend is in a motoko smart contract, I am coverting the images from bytes data to the blobs in my component like so:
const getAllProducts = async (): Promise<Product[]> => {
setLoading(true);
try {
const products = await marketplace_backend.getProducts();
const convertImage = (image: Uint8Array | number[]): string => {
const imageContent = new Uint8Array(image);
const blob = new Blob([imageContent.buffer], { type: "image/png" });
return URL.createObjectURL(blob);
};
const productsWithUrl = products.map((product) => ({
...product,
image: convertImage(product.image),
smallImages: {
image1: convertImage(product.smallImages.image1),
image2: convertImage(product.smallImages.image2),
image3: convertImage(product.smallImages.image3),
},
}));
setProducts(productsWithUrl);
console.log(productsWithUrl, "converted images");
setLoading(false);
return productsWithUrl;
} catch (e) {
setLoading(false);
console.log(e, "Error");
}
};
Maybe there is somewthing I should also do on the function here where the images are being converted and solve the problem?