Skip to content

Instantly share code, notes, and snippets.

@Gumball12
Created November 7, 2019 14:41
Show Gist options
  • Save Gumball12/205f53addb0cc5f371ded047b0261066 to your computer and use it in GitHub Desktop.
Save Gumball12/205f53addb0cc5f371ded047b0261066 to your computer and use it in GitHub Desktop.
server and client code for network term project
<!--
file upload client
@author shj
-->
<input type="file" />
<button>업로드</button>
<script>
// append event handler
document.querySelector('button').addEventListener('click', () => {
// get file binary
const file = document.querySelector('input').files[0];
// store into the form data
const data = new FormData();
data.append('data', file);
// print file size
console.log(
'upload file size:',
`${Math.floor((file.size / 1024) * 1000) / 1000}KB`,
);
// fetching to server (http://127.0.0.1:3000)
fetch('http://localhost:3000', { method: 'POST', body: data });
});
</script>
/**
* file upload server
* @author shj
*/
// import http module
const http = require('http');
// create server
http.createServer(( req ) => {
// print buffer
req.on('data', console.log);
}).listen(3000); // http://127.0.0.1:3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment