简体   繁体   中英

Upload and Retrieve Image in Node.js?

I'm new to nodejs. I'm trying to upload an image to the server and store that image path in the localhost's PostgresSQL database as like this ( myipaddress:3000/uploads/images/12345.png ).

I Learned to upload an image to the server as specified in this link

But I would like to load that image url separately in mobile device or in image tag as follows <img src="myipaddress:3000/uploads/images/12345.png">

Thanks in advance and Can any one please provide suggestions to access an uploaded image with its url in my express application

Follow this ( http://www.hacksparrow.com/handle-file-uploads-in-express-node-js.html ) to upload an image to server in nodejs.

Once you followed. It will return response like this

File uploaded to: ./public/images/85d15c2f7e812a03faa44bdef0ce41f5.png - 278070 bytes

The response shows that your image is stored in the public/images directory

Image Name : 85d15c2f7e812a03faa44bdef0ce41f5.png

Image Path : ./public/images/85d15c2f7e812a03faa44bdef0ce41f5.png

You can load the image with the server ip by removing the public from the URL. Because we can directly access the content from the public directory without specifying public.

So the following link is enough to load the image from the URL.

your-local-ip:port/images/85d15c2f7e812a03faa44bdef0ce41f5.png

eg:

http://localhost:3000/images/85d15c2f7e812a03faa44bdef0ce41f5.png

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM