-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
53 lines (46 loc) · 1.66 KB
/
Copy pathcontroller.js
File metadata and controls
53 lines (46 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const cloudinary=require('./cloudinaryConfig')
const upload_video = async (req, res) => { try {
console.log(req.file);
var videoFile = req.files.video;
// Assuming the file path is provided in the request body
console.log(videoFile);
if (!videoFile) {
throw new Error("Invalid file");
}
// Upload movie file to Cloudinary
const uploadResult = await cloudinary.uploader.upload(
videoFile.tempFilePath,
{
resource_type: "video",
folder: "movies", // Optional: Specify a folder in your Cloudinary account
}
);
// Return the movie URL and other details
const movieUrl = uploadResult.secure_url;
res.status(200).json({ movieUrl });
} catch (error) {
console.error("Failed to upload movie:", error);
res.status(500).json({ error: error.message || "Failed to upload movie" });
}}
const upload_photo = async (req, res) => { try {
var photoFile = req.files.photo;
// Assuming the file path is provided in the request body
if (!photoFile) {
throw new Error("Invalid file");
}
// Upload movie file to Cloudinary
const uploadResult = await cloudinary.uploader.upload(
photoFile.tempFilePath,
{
resource_type: "auto",
folder: "photos", // Optional: Specify a folder in your Cloudinary account
}
);
// Return the movie URL and other details
const posterUrl = uploadResult.secure_url;
res.status(200).json({ posterUrl });
} catch (error) {
console.error("Failed to upload poster:", error);
res.status(500).json({ error: error.message || "Failed to upload poster" });
}}
module.exports = { upload_video,upload_photo };