Spaces:
Sleeping
Sleeping
Download src/controllers/upload.controller.ts from underrate/webdev-service-backend: direct link, hf CLI and curl.
- Browser
- Download file 652 Bytes
-
https://huggingface.co/spaces/underrate/webdev-service-backend/resolve/main/src/controllers/upload.controller.ts
- Command line
-
hf download hf://spaces/underrate/webdev-service-backend/src/controllers/upload.controller.ts
-
curl -L -o upload.controller.ts https://huggingface.co/spaces/underrate/webdev-service-backend/resolve/main/src/controllers/upload.controller.ts
652 Bytes
| 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' }); | |
| } | |
| }; | |