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

194
Visualizações
Streaming files from server to electron/angular2 client using request library

I am creating a desktop application using angular2 and electron. This client needs to download zip files from a server using the request library.

To be able to download files is only the first step, The client application will also need to be able to push zip files to the server. Compared how easy this is using the examples below I dont understand what is blocking this.

To get the fs and path library to work in electron I had to do some workaround in the index.html. this workaround is currently working and I am able to create folders within my file system with fs:

 <script>
   window.fs = require("fs");
   window.path = require("path");
 </script>

Code

Server

const restify = require('restify');
const server = restify.createServer();
const fs = require('fs');

server.post('/download', function(req, res) {
  fs.createReadStream("C:\\test\\test.zip").pipe(res);
});

server.listen(1338, function() {
  console.log('server started up on port 1338');
});

Working Client

let request = require("request");
let path = require("path");
let fs = require("fs");

request.post("http://localhost:1338/download").on("response", (response) => {
    let zipLocation = path.join("/test", "response.zip");
    let writeStream = fs.createWriteStream(zipLocation);

    writeStream.on("finish", () => {
        console.log("finished");
    }).on("error", (err) => {
        console.log("err: ", err.message);
    });

    response.pipe(writeStream);
}).on("error", (err) => {
    console.log("req err: ", err.message);
});

But when I introduce this client code into the angular2 electron app. I get a error:

err:  Invalid non-string/buffer chunk

I have the request library included within my angular app as such:

import * as request from 'request';

This issue might be connected to the request library. in the response from there are no headers. But I am unable to say for sure

response.headers // is a empty object: {}

Can anyone tell me the reason for as why I am unable to stream files from the server to the file system running the electron app?

UPDATE:

After trying to implement file upload I got the same error:

Invalid non-string/buffer chunk
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