简体   繁体   English

使用 Parse Cloud 代码在 Heroku 文件系统中保存文件?

[英]Saving files in Heroku file system using Parse Cloud code?

I'm using Parse Server on Heroku and I'm wondering if I'm able to save files to heroku via cloud code.我在 Heroku 上使用 Parse Server,我想知道是否可以通过云代码将文件保存到 heroku。

Something like this:像这样的东西:

Cloud code (main.js):云代码(main.js):

Parse.Cloud.define("saveFile", function(request, response) {
    fs.writeFile("test", "helloworld", function(err) {
      if(err) {
          return console.log(err);
      }
      console.log("The file was saved!");
    }); 
}

then call this function via curl call in terminal:然后通过终端中的 curl 调用调用此函数:

curl -X POST -H "X-Parse-Application-Id: yourappid" -H “Content-Type: application/json" https://your-parse-server.herokuapp.com/parse/functions/saveFile curl -X POST -H "X-Parse-Application-Id: yourappid" -H "Content-Type: application/json" https://your-parse-server.herokuapp.com/parse/functions/saveFile

in heroku logs, I am able to see the console which prints "The file was saved", however, when I looked into the heroku /app directory (via heroku CLI: heroku run ls) the file "test" was not listed.在 heroku 日志中,我能够看到打印“文件已保存”的控制台,但是,当我查看 heroku /app 目录(通过 heroku CLI:heroku run ls)时,未列出文件“test”。

My questions:我的问题:

  1. Am I not able to create any file and save it to Heroku filesystem?我无法创建任何文件并将其保存到 Heroku 文件系统吗?
  2. Is the file saved, but the directory of the file is hidden from me?文件是否已保存,但文件目录对我隐藏了?
  3. Is there any way to verify that the file is saved?有什么方法可以验证文件是否已保存?
  4. Is there any way to access the created file (if it is saved)?有什么方法可以访问创建的文件(如果已保存)?

Thanks in advance!提前致谢!

No, this is not possible. 不,这是不可能的。 Heroku has an ephemeral filesystem . Heroku有一个临时文件系统

Whenever you deploy your app, they build a container on which that version of your code can run. 每当您部署应用程序时,它们都会构建一个容器,可以在其上运行该版本的代码。 That container is then fetched and run as dynos. 然后,获取该容器并以dynos的身份运行。
If you write files to the disk, they will not be persisted outside the currently running container (any other dyno won't have them and they will be permanently lost when the app is restarted/deployed). 如果将文件写入磁盘,它们将不会持久保存在当前运行的容器之外(任何其他dyno都不会拥有它们,并且在重新启动/部署应用程序时,它们将永久丢失)。

Any code change you wish to make to your application necessitates a new deployment. 您希望对应用程序进行的任何代码更改都需要进行新的部署。

so if the file saved, is a github repository, can i somehow get access to it, even if temporary just to parse, select/filter some files and do post requests to an api with the data selected ?因此,如果保存的文件是 github 存储库,我能否以某种方式访问​​它,即使只是临时解析、选择/过滤一些文件并使用选定的数据向 api 发布请求? even if that repo will be lost once the dyno restarts.即使一旦 dyno 重新启动,该 repo 就会丢失。

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

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