在Node.js中上载和检索图像? [英] Upload and Retrieve Image in Node.js?

查看:126
本文介绍了在Node.js中上载和检索图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是nodejs的新手。我试图将图像上传到服务器,并将该图像路径存储在localhost的PostgresSQL数据库中,如下所示( myipaddress:3000 / uploads / images / 12345.png ) 。

我学习了按照链接



但我想要在移动设备中单独加载该图片网址或在图片标记中,如下< img src =myipaddress:3000 / uploads / images / 12345.png>



预先感谢,并且任何人都可以提供建议,以便在我的快速申请中访问上传的图片及其网址。 按照这个( http://www.hacksparrow.com/ handle-file-uploads-in-express-node-js.html )将图片上传到nodejs中的服务器。



O你跟着走了。它会返回这样的响应

 文件上传到:./public/images/85d15c2f7e812a03faa44bdef0ce41f5.png  -  278070字节

响应显示您的图片存储在 public / images 目录中



图片名称: 85d15c2f7e812a03faa44bdef0ce41f5.png



图片路径:。 /public/images/85d15c2f7e812a03faa44bdef0ce41f5.png



您可以通过从URL中删除公共内容来将图像加载到服务器ip。因为我们可以直接访问公共目录中的内容而不指定public。



因此,以下链接足以从URL加载图像。



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



例如:



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


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

这篇关于在Node.js中上载和检索图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆