code: 5400, message: 'Bad request: incomplete multipart stream'

I’m trying to upload image on cloudflare and getting error - “code: 5400, message: 'Bad request: incomplete multipart stream”. I’ve my code below. It already took 4 hrs and no luck. Please help me if anyone knows the solution.

export const uploadImageOnCloudflare = catchAsync(
  async (req: Request, res: Response, next: NextFunction) => {
    const body = new FormData();
    const encoded = req.file!.buffer.toString('base64');
    const blob = await fetch(`data:image/jpeg;base64,${encoded}`).then((res) =>
      res.blob()
    );

    body.append('file', blob, 'image.jpg');
    const result = await fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type':
          'multipart/form-data; boundary=---011000010111000001101001',
        Authorization: 'Bearer MY_TOKEN',
        'X-Auth-Key': 'MY_KEY'
      },
      body,
    });

    result.json().then((json) => console.log(json, '9999'));  // Getting failure here
    res.status(StatusCode.SUCCESS).json({
      status: 'success',
    });
    next();
  }
);

This topic was automatically closed after 15 days. New replies are no longer allowed.