0

I write a script to fetch content from other site, and save it to my public/ directory. Due to my network's poor environment, I deployed it to Heroku and wish it do it instead of me doing it locally.

Just something simple like this

  movie_file = "#{Rails.root}/public/movie_list#{year}.json"
  File.open(movie_file, "w"){|f| f.write(JSON.pretty_generate($movie_list))}

However, when I run it in heroku(just a rake task), it seems like it can't write into the public/ directory, I get no such page error. And I find this answer: Problems with public directory when deploying Node.js app with Heroku

But the original article is unavaible in heroku, and I'm not sure if its still true.

I'm wondering: If there is any workaround that I can save it to the server (maybe something other than the public/), and then I can download it to my computer?

Or, Instead of wrting the file into public/, maybe I can upload it to other free space?

======================

UPDATE: Finally, I first save file to tmp, and then save it to Qiniu(An China counterpart as AWS), and you can save it to AWS

Community
  • 1
  • 1
ZK Zhao
  • 19,885
  • 47
  • 132
  • 206
  • Have you tried to write to 'tmp/'? Remember that it should be added to your repository, so that Heroku creates it – davids Jul 12 '15 at 14:56
  • @davids, but can file under `tmp/` be access throuh browser directly? Otherwise how can I download the file? – ZK Zhao Jul 12 '15 at 15:19
  • If you need further control of your app/server, including the filesystem, I would recommend you deploying your app in a VPS. For instance, you can get one free instance in Amazon AWS – davids Jul 12 '15 at 15:40
  • @davids that's good, I'm gonna try that later. – ZK Zhao Jul 12 '15 at 15:52

1 Answers1

2

The storage on an Heroku dyno should be regarded as ephemeral, as a dyno restart will cause saved files to disappear, and the file would not be visible from other dynos.

You should use the dyno to upload your files to permanent storage, such as AWS, from which you can download it through your browser.

No permanent filesystem for Heroku?

Community
  • 1
  • 1
David Aldridge
  • 51,479
  • 8
  • 68
  • 96