Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

192
Visualizações
Socket hang up Express and Nodejs

I am trying to upload a file to one of the folder in the sharefile so I am using their upload API method. I was able to compile a snippet to test whether the upload works but I keep getting socket hang up error. Can you guys please check the below code and let me know on what is it that I am doing wrong? And also if there is another way (easier or best practice) where I can upload a file

var url = ""+urlString;
var filePath = "D:/Analytics All Web Site Data Browser & OS 20161001-20170306.pdf";
var boundaryKey = Math.random().toString(16);

var r = request.post( {
  url: url,
  proxy: "http://localhost:3128"
}, function( err, res, data ) {
  console.log( "Finished uploading a file " + err + " :: " + res + " :: " + data );
});

r.setHeader('Content-Type', 'multipart/form-data; boundary="'+boundaryKey+'"');

r.write( 
  '--' + boundaryKey + '\r\n'
  + 'Content-Type: application/octet-stream\r\n' 
  + 'Content-Disposition: form-data; name="Analytics"; filename="Analytics All Web Site Data Browser & OS 20161001-20170306.pdf"\r\n'
);

fs.createReadStream('D:/Analytics All Web Site Data Browser & OS 20161001-20170306.pdf', { bufferSize: 1024 * 1024 })
  .pipe(r, { end: false })
  .on('end', function() {
    r.end('--' + boundaryKey + '--'); 
  });
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda