Created
November 7, 2019 14:41
-
-
Save Gumball12/205f53addb0cc5f371ded047b0261066 to your computer and use it in GitHub Desktop.
server and client code for network term project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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