I’m developing a typescript project which receive the uploaded files from users and I will pass some of the files to OpenAI API.
What I have is
const uploadedFile = {
fieldname: 'file',
originalname: 'my.csv',
encoding: '7bit',
mimetype: 'text/csv',
buffer: <Buffer e8 b2 ... 15264 more bytes>,
size: 15266
}
What I tried is
- Directly upload
const uploadedFile = await openai.files.create({
// @ts-expect-error ignore
file: uploadedFile,
purpose: 'assistants',
});
[Nest] 23161 - 03/20/2024, 11:17:56 AM ERROR [ExceptionsHandler] 413 The data value transmitted exceeds the capacity limit.
Error: 413 The data value transmitted exceeds the capacity limit.
Its size is only 15KB, hard to believe it exceeded the upload limit.
- Blob
const blob = new Blob([uploadedFile.buffer], { type: file.mimetype });
const uploadedFile = await openai.files.create({
// @ts-expect-error ignore
file: blob,
purpose: 'assistants',
});
// console.log(blog) is
Blob { size: 15266, type: ‘text/csv’ }
// The error message of openai.files.create
[Nest] 22537 - 03/20/2024, 10:38:13 AM ERROR [ExceptionsHandler] 400 ‘file’ is a required property
Error: 400 ‘file’ is a required property