Skip to content

Instantly share code, notes, and snippets.

@diorahman
Created March 2, 2012 11:18
Show Gist options
  • Save diorahman/1957860 to your computer and use it in GitHub Desktop.
Save diorahman/1957860 to your computer and use it in GitHub Desktop.
Secure upload easyxdm
<!doctype html>
<html>
<head>
<title>easyXDM</title>
<script type="text/javascript" src="easyXDM.debug.js">
</script>
<script type="text/javascript">
/**
* Request the use of the JSON object
*/
easyXDM.DomHelper.requiresJSON("json2.js");
</script>
<script type="text/javascript">
// this is just some bootstrapping code in order to provide
// the correct host name depending on where it is being run.
// var REMOTE = "https://secure-lynx.appspot.com"
var REMOTE = "http://localhost:8080"
var btn;
var remote = new easyXDM.Rpc({
remote: REMOTE + "/public/upload_rpc.html",
onReady: function(){
//display the upload form
var frm = document.getElementById("frmUpload");
frm.action = REMOTE + "/upload/image";
frm.style.display = "block";
btn = document.getElementById("btnSubmit");
frm.onsubmit = function(){
btn.disabled = "disabled";
};
}
}, {
local: {
returnUploadResponse: function(response){
// here you should call back into your regular workflow
btn.disabled = null;
alert(response.msg);
}
}
});
</script>
</head>
<body>
<script>
// rpc.returnUploadResponse({"test":"test"});
// console.log(remote);
</script>
<form id="frmUpload" method="POST" target="upload_target" enctype="multipart/form-data">
<input type="file" name="upload_file"/><input type="submit" id="btnSubmit" value="Upload file"/>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment