简体   繁体   English

将文件存储在Web服务器中

[英]Storing files in a webserver

I have a project using MEAN stack that uploads imagefiles to a server and the names of the images to db. 我有一个使用MEAN堆栈的项目,该项目将图像文件上传到服务器,并将图像名称上传到db。 Then the images are shown for users of the applications kinda like an image gallery. 然后,为应用程序的用户显示图像,就像图像库一样。

I have been trying to figure out an effiecent way of storing the imagefiles. 我一直试图找出一种有效的方式来存储图像文件。 atm im storing them under the angular application in a folder /var/www/app/files atm im将它们存储在角度应用程序下的文件夹/ var / www / app / files中

What are the usual ways of storing them in a cloud server like digital ocean, heroku and many others. 将它们存储在数字海洋,heroku等许多其他云服务器中的常用方法是什么。 Im a bit thrown off by the fact they offer many options for datastorage. 它们为数据存储提供了许多选项,这让我有点不满意。

Lets say that hundres of thousands of images were uploaded by the application to the server. 假设应用程序将数十万张图像上传到服务器。 Saving all of them in inside your front end app in a subfolder might not be the best solution? 将它们全部保存在子文件夹中的前端应用程序内部可能不是最佳解决方案? or am i wrong with this. 还是我错了。

I am very new to these webserver cloud services and how they actually operate. 我对这些Web服务器云服务及其实际运行方式还很陌生。

Can someone clarify on what would be the optimal solution. 有人可以澄清什么是最佳解决方案。

Thanks! 谢谢!

Saving all of them in inside your front end app in a subfolder might not be the best solution? 将它们全部保存在子文件夹中的前端应用程序内部可能不是最佳解决方案?

You're very right about this. 您对此非常正确。 Over time this will get cluttered, and unless you use some very convoluted logic, will slow down your server. 随着时间的流逝,这将变得混乱不堪,除非您使用一些非常复杂的逻辑,否则将会降低服务器的速度。

If you're using Angular and this is in the public folder sent to every user, this is even worse. 如果您使用的是Angular,并且它位于发送给每个用户的公用文件夹中,则情况更糟。

The best solution to this is using something like an AWS S3 Bucket (DigitalOcean has Block Storage and I believe Heroku has something a bit different). 最好的解决方案是使用类似AWS S3 Bucket的设备(DigitalOcean具有数据块存储,我相信Heroku有所不同)。 These services offer storage of files, and essentially act as logic-less servers. 这些服务提供文件存储,并且实质上充当无逻辑服务器。 You can set some privacy policies and other settings, but there's no runtime like NodeJS that can do logic for you. 您可以设置一些隐私策略和其他设置,但是没有像NodeJS这样的运行时可以为您做逻辑。

Your Node server (or any other server setup) interfaces with this storage server, and handles most of the fetching and storing of files. 您的节点服务器(或任何其他服务器设置)与此存储服务器连接,并处理大多数文件的获取和存储。 You can optionally limit these storage services so they can only communicate with your Node server, so any file traffic would be done through your Node server. 您可以选择限制这些存储服务,以便它们只能与您的节点服务器通信,因此任何文件通信都将通过您的节点服务器进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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