Name: js-handler/node_modules/restify/node_modules/formidable/test/tools/base64.html 
1:
<html>
2:
<head>
3:
  <title>Convert a file to a base64 request</title>
4:
 
5:
<script type="text/javascript">
6:
 
7:
function form_submit(e){
8:
  console.log(e)
9:
 
10:
  var resultOutput = document.getElementById('resultOutput');
11:
  var fileInput = document.getElementById('fileInput');
12:
  var fieldInput = document.getElementById('fieldInput');
13:
 
14:
  makeRequestBase64(fileInput.files[0], fieldInput.value, function(err, result){
15:
    resultOutput.value = result;
16:
  });
17:
 
18:
  return false;
19:
}
20:
 
21:
function makeRequestBase64(file, fieldName, cb){
22:
  var boundary = '\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/\\/';
23:
  var crlf = "\r\n";
24:
 
25:
  var reader = new FileReader();
26:
  reader.onload = function(e){
27:
    var body = '';
28:
 
29:
    body += '--' + boundary + crlf;
30:
    body += 'Content-Disposition: form-data; name="' + fieldName + '"; filename="' + escape(file.name)+ '"' + crlf;
31:
    body += 'Content-Type: ' + file.type + '' + crlf;
32:
    body += 'Content-Transfer-Encoding: base64' + crlf
33:
    body += crlf;
34:
    body += e.target.result.substring(e.target.result.indexOf(',') + 1) + crlf;
35:
 
36:
    body += '--' + boundary + '--';
37:
 
38:
    var head = '';
39:
    head += 'POST /upload HTTP/1.1' + crlf;
40:
    head += 'Host: localhost:8080' + crlf;
41:
    head += 'Content-Type: multipart/form-data; boundary=' + boundary + '' + crlf;
42:
    head += 'Content-Length: ' + body.length + '' + crlf;
43:
 
44:
    cb(null, head + crlf + body);
45:
  };
46:
 
47:
  reader.readAsDataURL(file);
48:
}
49:
 
50:
</script>
51:
 
52:
</head>
53:
 
54:
<body>
55:
 
56:
<form action="" onsubmit="return form_submit();">
57:
  <label>File: <input id="fileInput" type="file" /></label><br />
58:
  <label>Field: <input id="fieldInput" type="text" value="file" /></label><br />
59:
  <button type="submit">Ok!</button><br />
60:
  <label>Request: <textarea id="resultOutput" readonly="readonly" rows="20" cols="80"></textarea></label><br />
61:
</form>
62:
<p>
63:
Don't forget to save the output with windows (CRLF) line endings!
64:
</p>
65:
 
66:
</body>
67:
</html>