0

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!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Meaning the file is temporary right? If so, then is it possible to access this "temporary file" that was created by that function?
Yes, the file is temporary. The currently running process could access the file, yes. But you couldn't access it with heroku run, or once the app is restarted.
is the file saved in some hidden temp folder or something? because once i ran this code and the log says "The file was saved!", I tried heroku run ls on heroku console and I could not see the intended file. Am I missing something?
No, the file is not saved in some hidden folder. When you run heroku run, you get a new container. A new server, with the code you deployed, not the filesystem changes that were made. Only the process saving the file on disk can see it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.