new Product
{
Id = 2,
CategoryId = 2,
BrandId=5,
ProductName = "Galaxy S23",
Stock = 20,
Price = 24999,
CreatedTime = DateTime.UtcNow,
ProductImage= "C:\Users\serka\OneDrive\Masaüstü\Staj\Ecommerce\Core\ProductImages\s23ımage.jpg"
},
this is my entity session, I added the path to a product image and I want to reflect it on my website in react
export const getAllProducts = async () => {
try {
const response = await getProductlist();
const products = response.data.data.map((product) => ({
id: product.id,
name: product.productName,
brand: getBrandNameById(product.brandId),
price: product.price,
image: product.productImage,
}));
console.log(products);
return products;
} catch (error) {
console.error("ürün yükleme hatası", error.message);
return [];
}
};
const getProductlist = async () => {
try {
const response = await axios.get("https://localhost:7001/api/Product/All");
return response;
} catch (error) {
throw new Error("Ürünleri alma hatası: " + error.message);
}
};
<ul className="product-list">
{products.map((product) => (
<ProductItem
key={product.id}
imageSrc={product.image}
name={product.name}
brand={product.brand}
price={product.price}
/>
))}
</ul>
const ProductItem = ({ imageSrc, name, price, brand }) => {
console.log(imageSrc);
return (
<li className="product-item">
<a href="#">
<img src={imageSrc} alt="" className="product-image" />
<h3 className="Product-name"> {name} </h3>
<p className="product-price"> {price} TL</p>
<p className="product-brand"> Marka:{brand}</p>
<button className="product-cart-button"> Sepete Ekle </button>
</a>
</li>
);
};
Above are the productItem blocks where I transferred my seed, api connection and data to the peer, I cannot print my image on my page, what path should I follow?
I took an "https" link from google drive and assigned it, I also paid attention that the link was public, but I could not get an image again, I tried both ways with replaceAll to change the "//" signs to "" and "/", I have not found a solution yet, I am waiting for your help, thanks.
2
Answers
I converted my images into code via base64.guru and embedded them in my database in string type. Then on react side src={
data:image/*;base64, ${imageSrc}
} I did a process in the form of. I was able to open my images on my site by introducing the incoming base64 data.As far as I know, images from local drive (your device) can not be accessed through url. You have to upload the image in a bucket like s3 or on a folder (your projects public folder can be used) inside server. Then create a url for that image and pass that image url to the
<img/>
. That way you can access it.Any image outside public folder can not be accessed by the project without importing it first.