Así es como funciona mi API:
Puede encontrar SeaweedFS aquí en GitHub .
Y el código aquí:
// /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;Controlador MongoDB aún no implementado.
Cuando trato de OBTENER un archivo (usando Firefox, Hoppscotch dice Could not send request: Unable to reach the API endpoint. Check your network connection and try again. ), obtengo algo cuyo tipo MIME es application/octet-stream por alguna razón . Es más grande que el archivo original. Sé que debe haber algunos problemas con mi código, pero no sé dónde ni cómo solucionarlo.