File size: 652 Bytes
d53e5b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { Request, Response } from 'express';

export const uploadImage = (req: Request, res: Response) => {
    try {
        if (!req.file) {
            return res.status(400).json({ error: 'No file uploaded' });
        }

        // Return the URL path
        // In local development, this translates to the public URL served by Express static
        const imageUrl = `/uploads/${req.file.filename}`;

        return res.status(200).json({ url: imageUrl });
    } catch (error) {
        console.error('Upload Error:', error);
        return res.status(500).json({ error: 'Internal server error during file upload' });
    }
};