| 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' }); | |
| } | |
| }; | |