Skip to content

Instantly share code, notes, and snippets.

@blmarket
Created June 30, 2012 13:06
Show Gist options
  • Save blmarket/3023673 to your computer and use it in GitHub Desktop.
Save blmarket/3023673 to your computer and use it in GitHub Desktop.
Upload somewhat big file using nodejs http.client
var http = require('http');
var fs = require('fs');
var filename = process.argv[process.argv.length-1];
var filesize = fs.statSync(filename).size;
var boundary = "----FuckingBoundary12341234"
var options = {
host: '192.168.0.3',
port: '8080',
path: '/',
method: 'POST',
headers: {
'content-type': 'multipart/form-data; boundary=' + boundary,
'content-length': filesize
},
form: {
'file': filename
}
}
var req = http.request(options, function(res) {
//console.log(res);
res.on('data', function(chunk) {
console.log('BODY: ' + chunk);
});
});
req.on('error', function(err) {
console.log("upload err : " + err);
});
req.write("--" + boundary + "\r\n");
req.write('Content-Disposition: form-data; name="file"; filename="'+filename+'"\r\n\r\n');
req.write("--" + boundary + "\r\n");
req.write('Content-Disposition: form-data; name="button"\r\n\r\n');
req.write('Submit\r\n');
req.write("--" + boundary + "--\r\n");
fs.createReadStream(filename).pipe(req);
req.end();
@blmarket
Copy link
Author

으으으 망했어 망했다고! 파일 사이즈가 큰 경우에 끝부분이 제대로 전송이 안되고 있단 말이다 유ᅟᅲ 유유유윰 ᄋᅠ라먼이라ᅟᅥᆷᄂᅠ이ᅟᅡ러ᅟᅵᅟᅡᆫ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment