Hey there, I try to upload file using REST API but I get the same error over and over.
async function uploadFile() {
const config = {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'multipart/form-data'
},
body : JSON.stringify({
file: fs.createReadStream('content.txt'),
purpose: 'assistants'
})
};
let response = await fetch('https://api.openai.com/v1/files', config);
let result = await response.json();
console.log(result);
}
uploadFile();
Error below
{
error: {
message: "'file' is a required property",
type: 'invalid_request_error',
param: null,
code: null
}
}
According to the documentation request body should has two parameters: file and purpose and that is exactly what I do.
Could someone please point me what I do wrong or give me hint how I can solve it?