-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Developed the API for uploading user profile image (#34)
- Loading branch information
Showing
11 changed files
with
965 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const cloudinary = require('cloudinary').v2 | ||
const dotenv = require('dotenv') | ||
|
||
const config = dotenv.config() | ||
if (!config) { | ||
console.log(config.error) | ||
} | ||
|
||
cloudinary.config({ | ||
cloud_name: process.env.CLOUDINARY_CLOUD_NAME, | ||
api_key: process.env.CLOUDINARY_API_KEY, | ||
api_secret: process.env.CLOUDINARY_API_SECRET, | ||
}) | ||
|
||
module.exports = cloudinary |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { pool } = require('../database') | ||
|
||
function uploadProfileImage(req) { | ||
return new Promise((resolve, reject) => { | ||
if (!req.file) { | ||
return reject('File not uploaded') | ||
} else { | ||
const results = { profileImg: req.file.path } | ||
pool.query( | ||
'UPDATE user SET profile_img=? WHERE username=?', | ||
[results.profileImg, req.username], | ||
(error) => { | ||
if (error) { | ||
return reject(error) | ||
} | ||
return resolve(results) | ||
} | ||
) | ||
} | ||
}) | ||
} | ||
|
||
module.exports = uploadProfileImage |
Oops, something went wrong.