Question

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
Was it helpful?

Solution 2

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.

OTHER TIPS

I am not sure that you can really do file uploads from ajax. See this thread for more info:

How can I upload files asynchronously?

Forgetting about the ajax portion, and the server it will just look like a file upload. You can see this section of the crash course for information on file uploads:

http://happstack.com/docs/crashcourse/RqData.html#rqdataupload

Uploaded files are store in temporary files and automatically cleaned up after the Response is sent. So, if you do not need to store the files, then you can just read the contents of the temp file, and let the server automatically delete the files after the Response is sent.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top