20 May 2014
angularjs, directive, file, and javascript
A common component in web applications is the form <input type="file">.
To connect this input any kind of logic or just render a preview of the selected files tends to be a hassle involving a POST to some server-side code.
For some cases it would be a lot easier containing parts of this on the client-side.
After implementing this for various angular projects a pretty useful directive started to emerge.
Usage
Example
{{ file.name }}
How it works
Listen for change in input element.
For each targeted file:
Read the file as text or binary string.
Base64 encode body if file type is binary string.
Compile type, name & body.
Apply new values to $scope when last file is done.
For most of my projects I use Git as source control and store them on GitHub.
They offer a service called Github Pages where you can host static pages.
There you have a static page generator tool called Jekyll out of the box witch takes care of the most boring parts and a CDN in front for better hosting performance.
You can do this a number of ways and here here is one.