Insert image into HTML page using absolute path - html

I'm given a task to insert an image to an index2 HTML page using absolute path, however, I'm getting this error " Failed to load resource: net::ERR_FILE_NOT_FOUND." if I use this path "images/baby-01.jpg", but If I use the relative path given below, I'm able to load the image.
<img src="/Users/gill/Downloads/Lab1/lab1-part2-images/abs-path/images/baby-01.jpg" alt="baby 01"/>"
Image path
/Users/gill/Downloads/Lab1/lab1-part2-images/abs-path/images/baby-01.jpg
The path of the page I'm trying to insert the image into.
/Users/gill/Downloads/Lab1/lab1-part2-images/abs-path/local news/index2.html

The absolute path has to be the absolute URL path and not the absolute filesystem path.
The root of the path is the directory the web server is configured to treat as a root, not the file system that the web server is installed on (otherwise, anyone could download any file from any computer running a web server).

Related

Live server is not loading my images but when I open my file manually ex:index.html, my images are fully loaded

<div class="slide__Show1">
<h2>It's More Than Just A Sport</h2>
<p>Get back on the field in style!</p>
<img src='../E-commerce/IMG/Soccer.jpeg'>
</div>
Live server works as a real (remote) server, and looks for the image like a real server would do: Not on your local machine, but relative to the project root on your "server".
When you open a local HTML file on your computer/in your browser, it is able to look for the image file locally anywhere on your computer, and thus is a bit easier to satisfy.
So there's a slight difference which types of URLs/paths you can use in a local file and a file that is supposed to work on a server.
In your case, you need to use either an absolute path or a relative path.
Absolute path: https://examplesite.com/assets/img/soccer.jpg
Relative path: /assets/img/soccer.jpg
Your relative path goes one level UP (out) from the root folder of your project (because of ../) and searches for a file that is probably outside your website folder, in the E-commerce directory.

Image not showing in browser on local server (Live server extension) but shows when opened from explorer

I am having problem in HTML . My Image is not showing in browser (Firefox) when html file is opened through live server extension (VS code).It throws a Security error that html file can't link to image. I want to use image as background.
My html file is folder in D: drive.
Path = D:/myhtml/index.html
And my image is in F: drive
Path = F:/mountain.png
my img tag is
<img src="f:/mountain.png" alt="mountain"/>
But when I open html file directly from file explorer image shows up.
Please help to solve this problem.
Live server in made to behave like a real web server (one that is online on the web, called via http(s), and does not have access to your local hard drive file system "the Windows way" with F: etc.
Going to F:// is only possible on your own machine and will never work online. Browsers have built in a way for you to browse your local files like that. Web servers don't have this feature.
Use HTML file paths, meant for the web server:
Absolute path: https://example.com/images/mountain.png (path to an online destination which could be another domain than yours)
Relative path: images/mountain.png (relative to where your html file is located on your own web server)
Relative path to a folder outside of where your html is located: ../../etc/images/mountain.png

Image loading locally but not on heroku server

My code works fine on local deployment, but when uploaded to a heroku server, I get the error message "Failed to load resource: the server responded with a status of 404 (Not Found)" in relation to howling.jpg. Checking the directory with bash shows that the image is on my heroku server to be used but I can't figure out why it won't load it. My canvas in the html file loads without an issue.
html code of image
heroku bash displaying howling.jpg
Did you reference howling.jpg with a relative reference in your code?
If you used an absolute path the directory names may be different and you might not be able to locate your image.
What is your code that is accessing/calling the image location? can you post it here please
fixed by putting into an images folder and using app.use
fixed code

ReactJS loading images from filesystem outside project

I have an application where I store in database the image paths. The paths are relative to my file system, not to the project.
When I issue in React:
<img alt={this.props.alt} src={require('/fs/storage/images/logo.jpg')}/>
I´m getting the following error:
You attempted to import /fs/storage/images/logo.jpg which falls outside of the project
src/ directory. Relative imports outside of src/ are not supported.
You can either move it inside src/, or add a symlink to it from project's node_modules.
How can I solve that ? Where should I put the symlink that the message is suggesting ?
How you can read filesystem or db from react if it on client side?
Do you have server? That communicate with database?
You should read image on server and send in on client, where use it in React

Set absolute path for root directory in HTML on local filesystem

How can I use absolute paths in my website while testing on my local filesystem? I know that I can use / to access the root directory of my website. However, this works only when my website is on the server. I want to be able to use absolute paths on my local filesystem so that I can do proper testing before uploading.
Is there a way to set a variable to a root directory in HTML? Something similar to Linux where you can define a variable WEBPATH=/home/user/website. Thus I can use e.g src="WEBPATH/folder/file.html for all the files I use in my website and I can modify WEBPATH depending on whether I am testing locally or using the server root folder.
I am open to other workarounds as well.
I'm assuming you're using a file url to access your HTML in the browser, in which case an easy way to get absolute paths working is by using a local webserver to serve your site.
If you have Python 3 installed, you can run python3 -m http.server from the command line at your web root, and it will serve your site at localhost:8000.