adding aws upload to the create post api

This commit is contained in:
Will Baumbach
2025-07-26 13:06:35 -05:00
parent 2704577d39
commit 54e960eaf6
8 changed files with 663 additions and 12 deletions

View File

@@ -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