clojure - Open a client's plain text file on an HTML page -


how use html open file on client's machine plaintext (i.e., .cpp, .txt, or .html file)? want extract plain textfile user's machine html <textarea>. fyi, using hiccup, clojure, , webnoir generate html , server other options use process along.

you have 2 main options: upload file server served html content or use html 5's file api. this question addresses few more options (like applets, enabling drag-and-drop file api, etc.)


upload file

  1. have users choose file using <input type="file" .../> on 1 page
  2. upload file contents server.
  3. redirect different page show file contents
  4. serve uploaded file's contents in textarea on page.

pros:

  • this method pretty simple , straightforward.
  • you can scan file , heavy processing on server

cons:

  • trips server can time consuming.

html 5 solution

  1. have user choose file using <input type="file" .../>
  2. instead of posting contents, use javascript load file html 5 local storage (see code below)
  3. use javascript insert contents of file dom.

pros:

  • no trip server (faster)

cons:

  • any , validation/processing must done on client side in javascript. makes client heavier , allows users see/modify code (which might not need care about).

i grabbed code snippet this site, has examples of using file api:

function oninitfs(fs) {    fs.root.getfile('log.txt', {}, function(fileentry) {      // file object representing file,     // use filereader read contents.     fileentry.file(function(file) {        var reader = new filereader();         reader.onloadend = function(e) {            // contents, stored in 'this.result'        };         reader.readastext(file);     }, errorhandler);    }, errorhandler);  }  window.requestfilesystem(window.temporary, 1024*1024, oninitfs, errorhandler); 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -