Skip to content

Instantly share code, notes, and snippets.

@kjunichi
Created September 21, 2012 08:26
Show Gist options
  • Save kjunichi/3760371 to your computer and use it in GitHub Desktop.
Save kjunichi/3760371 to your computer and use it in GitHub Desktop.
RingoJS v0.8 FileUpload sample script
var meta ='<meta name="viewport" content="width=device-width, initial-scale=0.5, maximum-scale=1.0, user-scalable=no">';
var msg = '';
msg = msg + "<h2>test</h2>"+req.method;
msg = msg + "<p>"+req.queryString + "</p>";
var httpUtils = require('ringo/utils/http');
// ファイルアップロードか判定する。
if(httpUtils.isFileUpload(req.headers["content-type"])) {
var params = {};
httpUtils.parseFileUpload(req,params);
var base64 = require('ringo/base64');
msg=msg+"<img src="+"\"data:image/"+params['pics'].contentType +";base64,"
+base64.encode(params['pics'].value)+"\">";
}
var res={};
res.status="200";
res.headers={};
res.headers['content-type']="text/html";
res.body=["<html><head>",meta,"</head><body>",msg,"</body></html>"];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment