like-gold•15mo ago
Where's the bug - RestSharp or Voiceflow?
I have a client with a large document library and part of our requirement is uploading PDFs to the VF KB.
I have used the VF C# sample code here https://developer.voiceflow.com/reference/post_v3alpha-knowledge-base-docs-upload
Using this code I always receive a 400 Bad Request when uploading PDFs, however text files upload OK.
If the encoding of the PDF attachment is forced to text/plain then PDFs will upload but are not parsed correctly by the VF API with thousands of encoded characters, a 3 chunk file becomes a 1000 chunk file.
I contacted VF support, here is their response:
I got my colleague to review your code, and he said this issue may arise because you are manually passing a FormBoundary, while RestSharp usually handles multipart boundaries automatically. Additionally, because the .txt file upload is currently functional, this does not appear to be a bug, and is thus outside of the scope of Support.'My code' is actually 'their code'. I have tried with and without manually added form boundaries and the problem remains, also if it works for text and not PDFs then I can't see how form boundaries can be the issue. So my questions is: Can anybody get the Voiceflow RestSharp sample code to upload correctly encoded PDFs to the KB from outside the VF network? It should be noted: * Uploading using the VF website works OK. * Uploads work OK when I use the native HTTP client. * Uploading using RestSharp (as recommended by the documentation) from outside the VF network has the issue.
3 Replies
The Voiceflow Knowledge Base API allows you to upload documents in PDF, text, or docx format. Once uploaded, you can view the chunks using the GET Document Chunk Retrieval Knowledge Base API. The API also provides options to specify whether to overwrite existing data and to determine how granularly each document is broken up.
Here is a sample code snippet using RestSharp to upload a PDF:
In this code:
- The
Content-Type
is set to multipart/form-data
for the request.
- The AddFile
method is used to attach the PDF with the correct MIME type application/pdf
.
If you encounter any issues, please refer to the Voiceflow API documentation for more details.like-goldOP•15mo ago
This code does not compile (.NET 8.0, RestSharp 111.2.0) but with slight modification seems to work and uploads a PDF correctly.
It appears that in the last few hours the documentation has also been updated
Thank you!
what error message are you getting