Skip to content

Commit cbbc2d3

Browse files
author
shawon-majid
committed
stored images in the operating system's temp directory.
1 parent 150d8b5 commit cbbc2d3

12 files changed

Lines changed: 7 additions & 21 deletions

‎controllers/file-server.js‎

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,29 @@ const { getFile, deleteFile } = require("../services/aws/file-server");
22
const axios = require("axios");
33
const fs = require("fs");
44
const path = require("path");
5+
const os = require("os");
56

67
const getFileFromAWS = async (req, res) => {
78
try {
89
// check if the file exists, if so then send the file
910

10-
const root = __dirname + "/../";
11-
12-
let filePath = root + req.params.fileName;
11+
let filePath = os.tmpdir() + "/" + req.params.fileName;
1312
filePath = path.resolve(filePath);
14-
15-
console.log(filePath);
1613
if (fs.existsSync(filePath)) {
17-
console.log("file exists...");
18-
19-
console.log(filePath);
20-
2114
res.sendFile(filePath);
2215

2316
return;
2417
} else {
2518
const url = await getFile(req.params.fileName);
2619
const response = await axios.get(url, { responseType: "stream" });
2720
// save the file to the server
28-
const file = fs.createWriteStream(req.params.fileName);
21+
const file = fs.createWriteStream(
22+
path.resolve(os.tmpdir() + "/" + req.params.fileName)
23+
);
2924
response.data.pipe(file);
3025
res.setHeader("Content-Type", response.headers["content-type"]);
3126
response.data.pipe(res);
3227
}
33-
34-
// const url = await getFile(req.params.fileName);
35-
36-
// const response = await axios.get(url, { responseType: "stream" });
37-
38-
// // save the file to the server
39-
// const file = fs.createWriteStream(req.params.fileName + ".mp4");
40-
// response.data.pipe(file);
41-
42-
// res.setHeader("Content-Type", response.headers["content-type"]);
43-
// response.data.pipe(res);
4428
} catch (error) {
4529
console.log(error);
4630
res.status(500).send("Error getting file");
-172 KB
Binary file not shown.
-172 KB
Binary file not shown.
-134 KB
Binary file not shown.
-134 KB
Binary file not shown.
-132 KB
Binary file not shown.
-132 KB
Binary file not shown.
-114 KB
Binary file not shown.
-114 KB
Binary file not shown.
-149 KB
Binary file not shown.

0 commit comments

Comments
 (0)