-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ec7ce8
commit bbe8a85
Showing
13 changed files
with
335 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,26 @@ | ||
const config = require("cloudinary").config; | ||
const uploader = require("cloudinary").uploader; | ||
const dotenv = require("dotenv"); | ||
const cloudinary = require('cloudinary').v2; | ||
const dotenv = require('dotenv'); | ||
dotenv.config(); | ||
|
||
const cloudinaryConfig = (req, res, next) => { | ||
config({ | ||
cloudinary.config({ | ||
cloud_name: process.env.CLOUDINARY_CLOUD_NAME, | ||
api_key: process.env.CLOUDINARY_API_KEY, | ||
api_secret: process.env.CLOUDINARY_API_SECRET, | ||
}); | ||
next(); | ||
}; | ||
module.exports = { cloudinaryConfig, uploader }; | ||
|
||
const uploadImage = async (filePath) => { | ||
try { | ||
const result = await cloudinary.uploader.upload(filePath, { | ||
folder: 'canteen_images', // Specify the folder where images should be uploaded | ||
}); | ||
return result; | ||
} catch (error) { | ||
throw new Error('Error uploading image to Cloudinary'); | ||
} | ||
}; | ||
|
||
module.exports = { cloudinaryConfig, uploadImage }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
const multer = require("multer"); | ||
const multer = require('multer'); | ||
const storage = multer.memoryStorage(); | ||
const multerUploads = multer({ storage }).single("image"); | ||
const multerUploads = multer({ | ||
storage, | ||
limits: { fileSize: 50 * 1024 * 1024 } // Set limit to 50MB | ||
}).single("image"); | ||
|
||
module.exports = multerUploads; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.