Advertisement
aquiem

Untitled

Feb 14th, 2025
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | Source Code | 0 0
  1. app.get("/test2", (req, res) => {
  2.     const dbPath = path.resolve(path.resolve(DATABASE_DIRECTORY), "test.db");
  3.  
  4.     if (!fs.existsSync(dbPath)) {
  5.         console.error("Database file not found:", dbPath);
  6.         return res.status(404).send("Database file not found");
  7.     }
  8.  
  9.     console.log("Sending file:", dbPath);
  10.  
  11.     res.setHeader("Content-Type", "application/x-sqlite3");
  12.     res.setHeader("Content-Disposition", "attachment; filename=test.db");
  13.  
  14.     const fileStream = fs.createReadStream(dbPath);
  15.     fileStream.pipe(res);
  16.  
  17.     fileStream.on("error", (error) => {
  18.         console.error("Error streaming file:", error);
  19.         res.status(500).send("Error streaming database");
  20.     });
  21. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement