简体   繁体   English

通过Flask / Python / Heroku上传后在哪里找到文件?

[英]Where to find the file after uploading via Flask/Python/Heroku?

I followed the basic format of how to upload a file on the following question: Flask/Apache submit button for file upload 对于以下问题,我遵循了如何上传文件的基本格式: 用于文件上传的Flask / Apache提交按钮

And my web page now has an upload and submit button that, I believe, works (ie it doesn't go to an error page, but just goes back to the index.html form to submit a file again. 我的网页现在有一个“上传并提交”按钮,我相信它可以正常工作(即,它不会转到错误页面,而只是返回到index.html表单以再次提交文件。

My question is, I assume that a file is being uploaded somewhere. 我的问题是,我认为文件正在某处上载。 Where is it? 它在哪里? Is it on my harddrive (preferably not!) or in the web somewhere? 是在我的硬盘驱动器上(最好不是!)还是在网络上的某个地方? It would be really cool to be able to access that file in the python backend and then call a function on it. 能够在python后端访问该文件然后在其上调用一个函数真的很酷。 (Eventually, I would like to return a file, too, that the backend produces). (最终,我也想返回后端生成的文件)。

Can anyone help point me in the right direction? 谁能帮助我指出正确的方向? I guess my questions are: 我想我的问题是:

My code looks like the fixed code in the question I linked to. 我的代码看起来像我链接到的问题中的固定代码。

  1. Where is the file and how can I call it for use later in the .py document? 该文件在哪里?如何在以后的.py文档中调用该文件?
  2. If my file is on my hard drive in the /tmp/ folder, how do I change it so it just stays on the web? 如果我的文件位于/ tmp /文件夹中的硬盘驱动器上,如何更改它使其仅保留在网络上?
  3. How do I send a file back? 如何发回文件? Is it HTTP "PUT"? 是HTTP“ PUT”吗?
  1. The file is at 该文件位于

     filename = secure_filename(file.filename) file.save(os.path.join("/tmp/", filename)) 

which means whatever filename is, in the /tmp/ directory. 这表示/tmp/目录中的filename是什么。

  1. No. It should be in /tmp/ filename. 否。应该在/tmp/文件名中。 Although I don't think this is a valid location for heroku. 尽管我认为这不是heroku的有效位置。 I suspect you have to upload content to someplace else, like Amazon S3 or direct via node . 我怀疑您必须将内容上传到其他地方, 例如Amazon S3直接通过node

  2. The online location, such as S3 will have a url, which you embed into the html so it downloads directly. 在线位置(例如S3)将具有一个URL,您将该URL嵌入到html中,以便直接下载。 eg http://mybucket.s3.amazonaws.com/<filename> 例如http://mybucket.s3.amazonaws.com/<filename>

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

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