Search code examples
curlherokuparse-server

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.

Something like this:

Cloud code (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 -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.

My questions:

  1. Am I not able to create any file and save it to Heroku filesystem?
  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!


Solution

  • No, this is not possible. Heroku has an ephemeral filesystem.

    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.
    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).

    Any code change you wish to make to your application necessitates a new deployment.