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?
I’m getting this error: {
“error”: {},
“label”: “API Call”,
“message”: “Received null for "file[_readableState][awaitDrainWriters]"; to pass null in FormData, you must use the string ‘null’”
}
This finally makes correct request, but the content of the file is not there.
NodeJS.ReadableStream is what S3 client in AWS SDK v3 returns.
I’m really trying to avoid reading stream completely into memory as a Blob or Uint8Array, or god forbid save it on disk and load as the OpenAI library suggesting.
Let’s step back. OpenAI implemented api endpoint to upload files with form data. Which is a front-end friendly solution. All these attempts to make it work on server side are workarounds for the form uploads.
Openai folks, do you have plans for a scalable storage? E.g. chunked uploads.