Unknown model· unknown
from ShareGPT 90K (shared ChatGPT conversations)
I would like to send pdf in a web service as json in base 64. How to take a pdf that can…
Private research annotation
Sign in to add a private research label or note.
- User
I would like to send pdf in a web service as json in base 64. How to take a pdf that can be up to 20mb with multiple pages and split them to 4mb requests? written in dotnetShare Prompt
- Assistant
To send a PDF as JSON in base64 format in .NET and split it into multiple 4MB requests, you can use the following steps:
- Read the PDF file into a byte array:
arduinobyte[] pdfBytes = File.ReadAllBytes("path/to/pdf/file.pdf");- Encode the byte array into a base64 string:
cstring base64String = Convert.ToBase64String(pdfBytes);- Split the base64 string into chunks of 4MB:
csharpList<string> base64Chunks = new List<string>(); int chunkSize = 4 * 1024 * 1024; // 4MB for (int i = 0; i < base64String.Length; i += chunkSize) { int length = Math.Min(chunkSize, base64String.Length - i); string chunk = base64String.Substring(i, length); base64Chunks.Add(chunk); }