Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
Unexpected file transfer behaviour when building API using Express

Here is how my API works:

How my API works

You can find SeaweedFS here on GitHub.
And the code here:

// /drivers/seaweedfs.js Defines how API interacts with SeaweedFS
const { error } = require("console");
const http = require("http");
module.exports = class Weed {
  constructor(mserver) {
    this.mserver = new URL(mserver);
  }

  get(fileId) {
    return new Promise((resolve, reject) => {
      let options = {
        hostname: this.mserver.hostname,
        port: this.mserver.port,
        method: "GET",
        path: `/${fileId}`,
        timeout: 6000,
      };
      let data;
      const fileReq = http.request(options, (res) => {
        console.log(`Statuscode ${res.statusCode}`);
        res.on("data", (response) => {
          data += response;
        });
        res.on("end", () => {
          resolve(data);
        });
      });
      fileReq.on("error", () => {
        console.error(error);
        reject();
      });
      fileReq.end();
    });
  }
};

// /routes/file.js An Express router
const express = require("express");
const router = express.Router();
const Weed = require("../drivers/seaweedfs");
let weedClient = new Weed("http://localhost:60002");

router.get("/:fileId", (req, res) => {
    weedClient.get(req.params.fileId)
    .then(data=>{
        res.write(data)
        res.end()
    })
}
)

module.exports = router;

MongoDB driver not yet implemented.

When I try to GET a file(using Firefox, Hoppscotch says Could not send request: Unable to reach the API endpoint. Check your network connection and try again.), I get something whose MIME type is application/octet-stream for some reason. It's bigger than the original file. I know there must be some problems with my code, but I don't know where and how to fix it.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda