Upload a local file while the task is performed

I have an import utility that I would like to use to create records for the hero.

I want to use this to import data from a file on my development machine without having to check the file in the repository. Is there a way to do this with a rake task or a gem to a hero?

I could upload the file as a web form, which could time out, or I could store the file in S3, but that seems excessive.

Any easy way to do this?

+7
source share
3 answers

You can read the standard version on your computer.

heroku run rake whatever <./file 
+5
source

No, it’s not possible to access local files on your development machine from anything running with heroku run (which includes rake tasks, assuming you are on a cedar).

I applied the following approach:

  • seed data is stored in a repo and loaded using seed_fu

  • Unseeded data is uploaded to S3 via a web form and linked to the DataFile model using paperclip (a bit crowded, but I used it for images elsewhere). Then I can use rake tasks or pending jobs to process files. This is definitely a bit of overhead.

+2
source

I found a very simple approach to this - use gist for input. You copy and paste your data into gist, and then pass the link to the source text as a parameter for your task. Then, in the rake task, you open the remote file.

For example, if you upload a yaml file:

 YAML.parse(open(file_name)).to_ruby.with_indifferent_access 
+1
source

All Articles