1

I am currently working on a Facebook app, and I need to do the following: Create a hash containing "key", "user" and "link" fields. The link field should contain a string, that is the address of a json file.

Now, my problem is the following: I gather data from facebook and store it in the json file. How create a file DIRECLTY on heroku, somehow like a folder, when an event is dispatched (for example the user clicks on a button), and put the URL into the hash on the link field? My location should probably look like .../[user]/myfile.json

Or, if not heroku, can you please suggest another host where I can do the same thing?

Note: I am just getting started with databases, I have only very basic knowledge of SQL, and the database is not done yet. I don't know anything about postgres, but I can learn, if it is preferred. My app is mainly developed with php.

hakre
  • 193,403
  • 52
  • 435
  • 836
MihaiB
  • 129
  • 1
  • 4
  • 17

2 Answers2

3

As @hakre said, Heroku runs apps on an Ephemeral filesystem. This means your local storage will be lost when the instance restarts.

Depending on the data you want to be storing, there are several options to store it.

  1. Cookie: Send it back in a cookie and let the browser take care of it. This is viable if the data is created by the user and it expires at some point.
  2. PostgreSQL: If you are using an SQL database in your application, it could go there. Either as a deserialized row or a TEXT field.
  3. CDN: If the data is to be public to all, you could upload it to for example Amazon S3 or Rackspace CloudFiles and publish the container. Then you can refer to it by URL.
  4. Cloud storage: If the data needs some access control, you can still upload it to S3 or CloudFiles and pull it from there programmatically when it is requested. If there is a performance issue, you could cache it in Memcache or some of the other cache addons.
  5. Document database: MondoDB and CouchDB store data as JSON documents. Both have plenty of features. Writing and reading are elementary operations on both. If you need a version history, CouchDB does that for you (it stores all revisions of the JSON by default.
  6. Browser local storage: You can store data on the browser now that we have HTML5. It is a bit bleeding edge and will not work on some of the older browsers still around.

There are plenty of other ways of storing your JSON documents on places other than a file. These are just the tip of the iceberg.

ferrix
  • 763
  • 3
  • 14
  • I do need to store them in a file. The user should have access to the file so that he/she saves it, and after a while, uploads the file back so my app can handle it. Thanks for the tips. I will use S3 probably – MihaiB Mar 13 '13 at 18:03
  • Remember: uploading and downloading a file does not mean you have to store them in files. HTTP is just text with headers. – ferrix Mar 14 '13 at 12:54
  • Can you suggest something more efficient, please? What I am trying to do is the following: User saves data in a json file, and doesn't care where is it stored. After a while, he/she needs to upload that file somewhere else, and data from the file will be used – MihaiB Mar 14 '13 at 13:21
  • With those parameters, any of the methods will work. That is, also S3. – ferrix Mar 14 '13 at 13:27
  • Well, that's what I think I will do. I need it to be a static link, because the link will be saved in a hash in the database and the user will gain access to it with the key associated. Thank you – MihaiB Mar 14 '13 at 13:34
2

To create a file directly on heroku, you need to create the file in your source-tree and then it will be stored on heroku when you publish the application.

Naturally this does not work for files you want to create while your application runs. Heroku does not support creating files on runtime on the same server. At least not in a way that they will stay there because the file-system is not persistent (for anything that is not part of the source-tree).

You need to create these "files" in the database or in another remote locations like Amazon S3.

See as well:

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
  • My app should let the user get a json with data from its account and then get it later, so probably I will need to host them on Amazon 3S because the user should later be able to download it when introducing the key from the "key" field. Great answer, thanks a lot – MihaiB Mar 13 '13 at 07:11
  • Everything you need to store "for later" you need to put into a remote location, yes. Heroku doesn't keep it for longer. The [*Heroku Ephemeral filesystem*](https://devcenter.heroku.com/articles/read-only-filesystem) is the key point here. – hakre Mar 13 '13 at 07:13
  • Well, if I think about it, anyway it wouldn't be a good deal to store it on heroku, since there is only 100 Mb free space – MihaiB Mar 13 '13 at 07:15
  • If the data is JSON and you want to store it for a specific user, you could look into storing it to `MongoDB`, `CouchDB` or some of the other database storages. – ferrix Mar 13 '13 at 13:29