MCPcopy Create free account
hub / github.com/TGX-Android/Publisher / uploadHttpFile

Function uploadHttpFile

main.js:440–467  ·  view source on GitHub ↗
(url, filePath, httpHeaders, httpOptions, needBinary)

Source from the content-addressed store, hash-verified

438}
439
440function uploadHttpFile (url, filePath, httpHeaders, httpOptions, needBinary) {
441 return new Promise((accept, reject) => {
442 const parsed = new URL(url);
443 const protocol = (parsed.protocol === 'https:' ? https : http);
444
445 const file = fs.createReadStream(filePath);
446 const stat = fs.statSync(filePath);
447
448 const options = Object.assign({
449 host: parsed.host,
450 path: parsed.pathname + parsed.search,
451 method: 'POST',
452 headers: Object.assign({
453 'Content-Type': 'application/octet-stream',
454 'Content-Length': stat.size
455 }, httpHeaders || {})
456 }, httpOptions || {});
457
458 const req = protocol.request(options, (res) => {
459 toUtf8(res, (contentType, content) => {
460 accept({statusCode: res.statusCode, statusMessage: res.statusMessage, content, contentType});
461 }, needBinary);
462 });
463
464 req.on('error', reject);
465 file.pipe(req);
466 });
467}
468
469function toUtf8 (res, onDone, needBinary) {
470 const contentType = (res.headers['content-type'] || '').split(';');

Callers 1

uploadGitHubAssetFunction · 0.85

Calls 1

toUtf8Function · 0.85

Tested by

no test coverage detected