Upload image axios + nest.js

Hi.

My request

await this.httpService
        .post(
          `https://api.cloudflare.com/client/v4/accounts/${this.configService.get(
            'cloudflare.image.accountId',
          )}/images/v1`,
          { file: file },
          {
            headers: {
              Accept: 'application/json',
              'Content-Type': 'application/json',
              Authorization: `Berear ${this.configService.get(
                'cloudflare.image.token',
              )}`,
            },
          },
        )
        .toPromise();

error

"message": "Request failed with status code 400",
    "name": "AxiosError",
    "stack": "AxiosError: Request failed with status code 400\n    at settle (/usr/src/app/node_modules/axios/lib/core/settle.js:19:12)\n    at IncomingMessage.handleStreamEnd (/usr/src/app/node_modules/axios/lib/adapters/http.js:556:11)\n    at IncomingMessage.emit (node:events:525:35)\n    at endReadableNT (node:internal/streams/readable:1359:12)\n    at processTicksAndRejections (node:internal/process/task_queues:82:21)",

A 400 generally implies that the data you sent isn’t valid in some way.

Can you share the JSON API response when this error happens?

shure


{
    "message": "Request failed with status code 400",
    "name": "AxiosError",
    "stack": "AxiosError: Request failed with status code 400\n    at settle (/usr/src/app/node_modules/axios/lib/core/settle.js:19:12)\n    at IncomingMessage.handleStreamEnd (/usr/src/app/node_modules/axios/lib/adapters/http.js:556:11)\n    at IncomingMessage.emit (node:events:525:35)\n    at endReadableNT (node:internal/streams/readable:1359:12)\n    at processTicksAndRejections (node:internal/process/task_queues:82:21)",
    "config": {
        "transitional": {
            "silentJSONParsing": true,
            "forcedJSONParsing": true,
            "clarifyTimeoutError": false
        },
        "adapter": [
            "xhr",
            "http"
        ],
        "transformRequest": [
            null
        ],
        "transformResponse": [
            null
        ],
        "timeout": 0,
        "xsrfCookieName": "XSRF-TOKEN",
        "xsrfHeaderName": "X-XSRF-TOKEN",
        "maxContentLength": -1,
        "maxBodyLength": -1,
        "env": {},
        "headers": {
            "Accept": "application/json",
            "Content-Type": "application/json",
            "Authorization": "Berear REDACTED",
            "User-Agent": "axios/1.3.4",
            "Content-Length": "2016581",
            "Accept-Encoding": "gzip, compress, deflate, br"
        },
        "method": "post",
        "url": "https://api.cloudflare.com/client/v4/accounts/2d34a1b27bzxczewr5e9etrc2ce46b704b0/images/v1",
        "data": "{\"file\":{\"fieldname\":\"file\",\"originalname\":\"c8f910ab-cefe-561f-b555-fdb4f85a6552.jpeg\",\"encoding\":\"7bit\",\"mimetype\":\"image/jpeg\",\"buffer\":{\"type\":\"Buffer\",\"data\":[255,216,255,224,0,16,74,70,73,70,0,1,1,0,0,217]},\"size\":565270}}"
    },
    "code": "ERR_BAD_REQUEST",
    "status": 400
}