Error loading image via Web API

Asked

Viewed 58 times

-2

I have a Rest API and it returns all the data of a user, including their image. I can find the image in the directory path, but I can’t click on the page.

Html

<img src="../../../../../../wwwroot/arquivos/defaultM.png">

I let this defaultM.png to make it easier to visualize, there is actually always a variable, but even so, it doesn’t work for both.

Error

Failed to load resource: the server responded with a status of 404 (Not Found) defaultM.png:1

What should I do in this case?

The image exists in the directory! And the way is right, I can even view the image by itself src using ctrl + click

  • The API returns the relative path of the image? already tried to see in the network tab of your browser which the Status the image returns?

  • This relative path does not seem correct, but without an overview of what is being done, it is impossible to find out. The same with the image by the API. Without knowing its folder/file structure and what the API is returning, it is impossible.

  • @Thiagocosta the API returns this: Failed to load Resource: the server responded with a status of 404 (Not Found) defaultM.png:1 | But this image exists on my server, it’s there.

1 answer

0

Based on the comments, apparently the API is not finding the file directory (404 code error usually means it was not found or does not exist). Remember, the directory has to be informed in the attribute src according to where your file is .html.

Without looking at the organization of your files, or the rest of the code is a little difficult to have exact accuracy, but probably the correct directory should be this:

<img src="arquivos/defaultM.png">

Hope I helped, hugs!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.