I’m struggling to upload a file directly from the client. In the documentation the create function uses fs.createReadStream(filePath) to create a stream of the file (which uses the file system) but I need to send the file selected by the user via the file select input field so the file never goes to the file system. So I send the file as FormData() to the endpoint and then try to create a read stream of it but I get this error that it does not support it. I have also tried to directly set the Buffer i get from the client to the file key in the create object but then I get an error saying that the value transmitted exceeds the capacity limit even though the file is not too big (it is 43KB and the limit is 512MB):
The buffer directly:
const file = await openai.files.create({
file: fileData // Buffer from the client,
purpose: "some purpose here",
});
Creating a stream of the buffer:
const stream = Readable.from(fileData); // fileData is the buffer from the client
const file = await openai.files.create({
file: stream, // Pass the stream for the file upload
purpose: "some purpose here",
});
Is there a workaround / fix to this? Or should I write the file to a temporary folder and then create the read stream from there with the fs.createReadStream() or what is the best practise?