0

I have my images into my images folder in my project and save the image name to my database. I can retrieve my images in my razor view like that. where FoodImage is the name of the image and I've hardcoded the path (~/~/Images/FoodImage/{image name from database}). code:-

<img src="~/Images/FoodImage/@Model.FoodImage" id="foodImage_upload_preview" alt="upload" width="250" height="150" />

Now I need to send this image URL via API from my server. But I don't know how to do that.

my apiend point: http://localhost:50833/api/getProducts and response:

[
{
    "id": 16,
    "title": "Product Rafi+++",
    "description": "sdfsf",
    "sku": "sdfsdf",
    "cardImage": "01_01_2020_12_14_09jukka.jpg",
    "foodImage": "01_01_2020_12_14_09jukka.jpg",
    "price": 52
},
{
    "id": 17,
    "title": "rAFI",
    "description": "SDFSD",
    "sku": "fdf",
    "cardImage": "01_01_2020_12_35_41jukka.jpg",
    "foodImage": "01_01_2020_12_35_41jukka.jpg",
    "price": 52
}
]

So how can I send an image URL from my server?

1
  • Does the API return the name of the image file? If yes, then make a call to API from your controller and store in your view model, then iterate through results. Commented Jan 1, 2020 at 9:34

1 Answer 1

2

You don't need to hard code into the database. When uploading the file, you can simply store the path to the image.

So, when calling the getProducts() endpoint, you won't need to worry about the image path.

Example:

var imagePath= Path.Combine(Directory.GetCurrentDirectory(), "Images", fileName);
//Upload the file
//Other logic
var product=new Product
{
foodImage=imagePath;
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.