I'm trying to send a blob image, but I'm getting Error: Unexpected end of form using multer with Serverless Framework.
My understanding is I have to append it to FormData before sending it in the body, but I haven't been able to get backend to accept file without crashing
    uploadImage(imageData: File) {
        console.log('IMAGE DATA', imageData);
        let formData = new FormData();
        formData.append('file', imageData, 'file.png');
        let headers = new HttpHeaders();
        headers.append('Content-Type', 'multipart/form-data');
        headers.append('Accept', 'application/json');
        let options = { headers: headers };
        const api = environment.slsLocal + '/add-image';
        const req = new HttpRequest('PUT', api, formData, options);
        return this.http.request(req);
    }
backend
const multerMemoryStorage = multer.memoryStorage();
const multerUploadInMemory = multer({
    storage: multerMemoryStorage
});
router.put(
    '/add-image',
    multerUploadInMemory.single('file'),
    async (req, res: Response) => {
        try {
            if (!req.file || !req.file.buffer) {
                throw new Error('File or buffer not found');
            }
            console.log(`Upload Successful!`);
            res.send({
                message: 'file uploaded'
            });
        } catch (e) {
            console.error(`ERROR: ${e.message}`);
            res.status(500).send({
                message: e.message
            });
        }
        console.log(`Upload Successful!`);
        return res.status(200).json({ test: 'success' });
    }
);
app.ts
import cors from 'cors';
import express from 'express';
import routers from './routes';
const app = express();
import bodyParser from 'body-parser';
app.use(cors({ maxAge: 43200 }));
app.use(
    express.json({
        verify: (req: any, res: express.Response, buf: Buffer) => {
            req.rawBody = buf;
        }
    })
);
app.use('/appRoutes', routers.appRouter);
app.use(
    bodyParser.urlencoded({
        extended: true  // also tried extended:false
    })
);
export default app;
From my understanding with serverless framework I have to install
npm i serverless-apigw-binary
and add
    apigwBinary:
      types: #list of mime-types
        - 'image/png'
to the custom section of the serverless template yaml file. The end goal is not to save to storage like S3, but to send the image to discord.
What am I missing? I appreciate any help!


 
     
     
    