Search code examples
jqueryajaxhappstack

Happstack jQuery and plain text file content


I'm trying on a Happstack-build website to read out "user submitted" plain text files. The main functionallity should be to get the file content, for further usage a server side storage of the file isn't needed.

  • What would be the way to realize this?
  • Does the file need to be uploaded or could ajax handle it, and if not, why?
  • A sample implementation would be helpful

Solution

  • This solution (using jQuery) was found, which is only HTML 5 supported:

    $("#uploadbutton").change(function() {
        var reader = new FileReader();
        reader.onloadend = function() {
            $("#output").val(reader.result);
        }
        reader.readAsText(this.files[0]);
    });
    

    The textfile content (selected via "#uploadbutton") is read out and shown in "#output". No Happstack file upload was needed.