-
Notifications
You must be signed in to change notification settings - Fork 0
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
d3afd4e
commit a14d248
Showing
5 changed files
with
230 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -36,7 +36,7 @@ const app = express() | |
} | ||
catch(error){ | ||
console.error("ERROR: ",error) | ||
throw err | ||
throw err; | ||
} | ||
})() | ||
|
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//In this we save the file in our server then we upload it on cloudinary | ||
|
||
import multer from "multer"; | ||
|
||
const storage = multer.diskStorage({ | ||
destination: function(req,res, cb){ | ||
cb(null , "./public/temp") // in temp all the files are getting stored | ||
}, | ||
filename: function (req, file, cb){ | ||
cb (null, file.organisation) //the filename has same as orginal filename uploaded by user | ||
} | ||
}) | ||
|
||
export const upload = multer ({ | ||
storage, | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { v2 as cloudinary } from "cloudinary"; | ||
import fs from "fs"; //This id used for file handling it is inbuilt package of node for file operation fs stands for file system | ||
|
||
cloudinary.config({ | ||
cloud_name: process.env.CLOUDINARY_CLOUD_NAME, | ||
api_key: process.env.CLOUDINARY_API_KEY, | ||
api_secret: process.env.CLOUDINARY_API_SECRET, | ||
}); | ||
|
||
const uploadOnCloudinary = async (loacalFilePath) => { | ||
try { | ||
if (!loacalFilePath) return null; //check if no file is selected to upload | ||
|
||
//upload on cloudinary | ||
const response = await cloudinary.uploader.upload(localFilePath, { | ||
resource_type: "auto", // set the file type can be upload | ||
}); | ||
//file uploaded successfully | ||
console.log("File uploaded successfully on cloudinary !!!", reponse.url); | ||
return response; | ||
} catch (error) { | ||
fs.unlinkSync(localFilePath); // remove the locally saved temporary file as the upload operation got failed | ||
return null; | ||
} | ||
}; | ||
|
||
export { uploadOnCloudinary }; |