mirandamon.
07/01/2024, 2:51 AMNode.js
code I'm trying to use (note that context.fetcher.fetch() is a Coda-specific fetch function):
const form = new FormData();
form.append("file", knowledgeBaseText);
let response = await context.fetcher.fetch({
url: "https://api.vapi.ai/file",
method: "POST",
headers: { ...form.getHeaders() },
body: form.getBuffer(),
});
However, when I use getBuffer, I get an error:
400 - {"message":"File is required","error":"Bad Request","statusCode":400}
Is it possible to have the POST /file endpoint accept the form buffer? I'm not able to send in the form as the body, and I'd like to have the buffer and the entire form work interchangeably.
Thanks in advance for the help,Vapi
07/01/2024, 2:53 AMFormData
to construct your request body for file uploads. However, the error you're encountering indicates that the server is not receiving the file data as expected.
When appending the file to the FormData
, make sure that the second parameter is a Buffer
or a Stream
that represents the file data, and also includes a filename in the options. Here's an example of how you might adjust your code:
javascript
const form = new FormData();
form.append("file", knowledgeBaseText, { filename: "knowledge-base.txt" });
let response = await context.fetcher.fetch({
url: "https://api.vapi.ai/file/upload", // Make sure the URL is correct
method: "POST",
headers: {
...form.getHeaders(),
'Authorization': 'Bearer YOUR_ACCESS_TOKEN', // Ensure you include the authorization header
},
body: form, // Use the form directly instead of getBuffer()
});
Please replace 'YOUR_ACCESS_TOKEN'
with your actual access token and ensure that the knowledgeBaseText
variable contains the file data as a Buffer
or Stream
. Also, specify the correct filename in the options object.
If you continue to face issues, please ensure that the endpoint URL is correct and that you have the necessary permissions to upload files. If the problem persists, please ask support for more info on this.Vapi
07/01/2024, 2:53 AMSahil
07/01/2024, 3:42 PMSahil
07/01/2024, 3:42 PMmirandamon.
07/02/2024, 12:17 AMheaders: { ...form.getHeaders() },
actually gives the multipart/form-data headermirandamon.
07/02/2024, 12:18 AM{ filename: "knowledge-base.txt" }
in the form.append() fixed the issuemirandamon.
07/02/2024, 12:46 AMmirandamon.
07/02/2024, 12:47 AMmirandamon.
07/02/2024, 12:47 AMShubham Bajaj
07/02/2024, 1:30 AMmirandamon.
07/02/2024, 1:38 AMShubham Bajaj
07/02/2024, 2:25 AM