Size Limitation for %ToJSON() with large stream
Hello everyone
Here is a try of sending a stream object with %ToJSON() by HTTP POST request on a remote server.
First the JSON structure:
{
"document": {
"id": "{43495441-4445-4C4C-4500-0500129C762E}",
"patient_id": "5003171TC01",
"language": "fr",
"doc_type": "CONS",
"doc_time": "2019-06-12 11:02:00",
(...)
"Sections": [
{
"sectionId": "main",
"Content": “eyJkb2N1bWVudCI6eyJpZCI6Ins0MzQ5NTQ0MS00NDQ1LTRDNEMtNDUwMC0wNTAwMTI5Qzc2MkV9\r\nIiwicGF0aWVudF9pZCI6IjUwMDMxNzFUQzAxIiwibGFuZ3VhZ2UiOiJmciIsImRvY190eXBlIjoi\r\nQ09OU(...)"
}
]
}
}
Actually the Content property must contain what is inside a base64 stream (e.g. from a PDF file, see code below). No problem for regular small files. But for large ones (up to 60 MB) this property is truncated to a maximum size of 32 kB.
What could we do for removing this size limitation for large streams ?
Here are some lines from the used code:
set httpRequest = ##class(%Net.HttpRequest).%New()
set httpRequest.Server = …..
set httpRequest.Port = ….
set httpRequest.Https = 0
set objDoc = {}
set objInObjDoc = {}
set arr = []
set objInArrMain = {}
set objInArrMain."sectionId" = "main"
do fileStreamBase64.Rewind()
set objInArrMain."Content" = fileStreamBase64.Read()
do arr.%Push(objInArrMain)
set objInObjDoc."id" = request.id
set objInObjDoc."patient_id" = request.patNdos
set objInObjDoc."language" = "fr"
(...)
set objInObjDoc."Sections" = arr
set objDoc."document" = objInObjDoc
set httpRequest.ContentType="application/json"
do httpRequest.EntityBody.Write(objDoc.%ToJSON())
set sc=httpRequest.Post("/index/push", 0)
- Building fileStreamBase64:
set fileStream = ##class(%Stream.FileCharacter).%New()
set fileStreamBase64 = ##class(%Stream.FileCharacter).%New()
set file=##class(%File).%New(completedFilename)
Do file.Open("RU")
Set sc=fileStream.CopyFrom(file)
Do file.Close()
Do ##class(HS.Util.StreamUtils).Base64Encode(fileStream,.fileStreamBase64)
Best regards,
Mathieu