我正在尝试将图像上传到 Cloudflare images,但出现错误,我不知道为什么。
我的要求
async uploadFile(
file: Express.Multer.File,
dto: UploadImageOptionsDto,
): Promise<any> {
try {
// const formData = new FormData();
// formData.append('file', file);
const response = await this.httpService
.post(
`https://api.cloudflare.com/client/v4/accounts/${this.configService.get(
'cloudflare.image.accountId',
)}/images/v1`,
{ file },
{
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: `Berear ${this.configService.get(
'cloudflare.image.token',
)}`,
},
},
)
.toPromise();
return response;
} catch (e) {
return e;
}
}
我在响应中收到以下错误
"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)",