Upload and Retrieve Image in Node.js?

前端 未结 1 1960
南旧
南旧 2021-02-06 17:20

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/

相关标签:
1条回答
  • 2021-02-06 17:46

    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

    0 讨论(0)
提交回复
热议问题