Search code examples
c#asp.net-coreasp.net-web-apiplesk

How to view the image that is in the wwwroot of the asp.net core api over the internet


I created an asp.net core api that some of the payload accepts images.

These images are stored in wwwroot/image of the application's folder, and the absolute path is stored in the database.

When testing locally, I can access the image from the path and see the image. I finally deployed to the host using Plesk and can no longer get the images.

A sample response carrying returning images:

{
  "responseCode": "00",
  "responseMessage": "sucessfull",
  "response": {
    "examinationBodies": [
      {
        "id": 2,
        "name": "Jamb",
        "description": "Joint Admission Matriculation Board",
        "imageUrl": "C:\\Users\\**********\\source\\repos\\Rikudouensof\\AinsExaminations\\AinsExaminations.Api\\wwwroot\\Images/ExaminationBodies\\Jamb.jpeg"
      },
      {
        "id": 3,
        "name": "WAEC",
        "description": "The West African Examination Council",
        "imageUrl": "https://api.ainsexamination.com\\wwwroot\\Images/ExaminationBodies\\WAEC.jpg"
      }
    ]
  }
}

Below are the sample results on a .net maui application enter image description here

I have gone to Plesk and gone to the folder, I have tried to see if I need to give permission. All permission has been given. still no hope.

Kindly help


Solution

  • Thanks to @iSR5, I found a way to solve it.

    Like he commented, the

    Ensure you added UseStaticFiles to your app services.

    I went to the Program.cs of the API, and added the following line of code;

    app.UseStaticFiles();
    

    Please note that this is a .Net core 8 API. enter image description here