Flask 上传中的 UPLOADS_DEFAULT_URL 配置值是什么意思?

What does UPLOADS_DEFAULT_URL configuration value in flask uploads mean?

来自this page

UPLOADS_DEFAULT_URL

If you have a server set up to serve from UPLOADS_DEFAULT_DEST, then set the server’s base URL here. Continuing the example above, if /var/uploads is accessible from http://localhost:5001, then you would set this to http://localhost:5001/ and URLs for the photos set would start with http://localhost:5001/photos. Include the trailing slash.

但是,你 不必设置任何 _URL 设置 - 如果您不这样做,那么他们 将由 Flask 内部提供。他们就在那里,所以如果你有 上传流量大,你可以有一个更快的生产服务器,比如 Nginx 或 Lighttpd 服务于上传。

我不明白 Flask 是如何使用的UPLOADS_DEFAULT_URL。文本说如果你不指定它,上传将由 flask 在内部提供。问题:

  1. 如果我不指定 url,它们将由烧瓶提供什么 url?
  2. 如果我指定 URL 将用它做什么烧瓶?它将如何使用它?

所以更容易回答我的问题:我不知道 python 究竟是如何与网络服务器(如 apache 或 nginx)交互的。我确实理解,原则上您希望这些 Web 服务器 front/proxy 您 python 应用 scalability/load 但我不知道如何完成此操作的确切细节。可能如果我知道的话,上面的信息对我来说会更明显。

从实用的角度来看:我有别人的python/flask app, and not a lot of experience with python. The parameter above needs to be specified in the config files。我启动了应用程序 运行,我没有指定这个特定参数,上传工作正常。我想知道如果不指定 URL.

我还能破坏什么

On what url are they going to be served by flask if I don't specify the url?

从文档我了解到,如果你这样设置

UPLOADS_DEFAULT_DEST = '/var/uploads/'
UPLOADS_DEFAULT_URL = 'http://localhost:5000/'

然后当你上传一组名为 photos 的照片时,会将其上传存储在 /var/uploads/photos 中。让我们假设它是 /var/uploads/photos/test.jpg。然后 flask 将以

的形式提供图像
http://localhost:5000/photos/test.jpg.

If I do specify URL what flask is going to do with it? How is it going to use it?

如果

UPLOADED_PHOTOS_DEST = '/var/mypics/'
UPLOADED_PHOTOS_URL =  'http://localhost:5000/'

然后当您上传一组名为 photos 的照片时,会将其上传存储在 /var/mypics/ 中。让我们假设它是 /var/mypics/test.jpg。然后 flask 会将图像作为

http://localhost:5000/test.jpg.

但我们不会在 production 中使用它。在生产图像中,静态应该由 nginxapache

提供