adding aws upload to the create post api
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import AWSUtil from '../bin/aws.js';
|
||||
import Post from '../models/postModel.js';
|
||||
|
||||
export const getAllPosts = async (req, res, next) => {
|
||||
@@ -31,7 +32,18 @@ export const getAllPostsByUser = async (req, res, next) => {
|
||||
}
|
||||
|
||||
export const createPost = async (req, res, next) => {
|
||||
Post.create(req.body).then(result => {
|
||||
const aws = new AWSUtil();
|
||||
|
||||
// Grab base64 photo from the req body
|
||||
const {location} = aws.uploadFile(req.body.photo, 'photos');
|
||||
|
||||
const payload = {
|
||||
...req.body,
|
||||
photo: location
|
||||
}
|
||||
|
||||
|
||||
Post.create(payload).then(result => {
|
||||
res.status(200).json({
|
||||
status: 'success',
|
||||
data: result
|
||||
|
||||
Reference in New Issue
Block a user