Search code examples
phpherokufilesystemshostinghost

Hosting files on heroku


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.


Solution

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