Hey guys, this seems like a common issue but I can't seem to find a clear solution.this is the logs from heroku2020-09-08T11:26:24.218417+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=POST path="/api/upload" host=ridenodejs.herokuapp.com request_id=be82c1a6-b520-4add-a3e7-90aa34d13b0d fwd="31.9.132.38,31.9.132.38" dyno=web.1 connect=1ms service=3591ms status=503 bytes=248 protocol=httpand here is my codeimport multer from 'multer';import { Request, Response, NextFunction } from 'express';import { Driver } from 'models';const storage = multer.diskStorage({destination: (req, file, cb) => {cb(null, 'uploads/'); },filename: (req, file, cb) => {cb(null, Date.now() + file.originalname); },});const fileFilter = (req: any, file: any, cb: any) => {if (file.mimetype === 'image/jpg' ||file.mimetype === 'image/png' ||file.mimetype === 'image/jpeg' )cb(null, true);else cb(null, false);};export const upload = multer({storage: storage,limits: {fileSize: 1024 * 1024 * 10, },fileFilter: fileFilter,});export const uploadImage = async (req: Request,res: Response,next: NextFunction) => {const {//@ts-ignoredata: { _id }, } = req.headers;const { type } = req.body;type === 'license'? await Driver.query().findById(_id!).patch({license: req.file.path, }): await Driver.query().findById(_id!).patch({identity: req.file.path, });res.send({status: 200,message: req.file, });};
Submitted September 08, 2020 at 12:36PM by YazanKhatib
No comments:
Post a Comment