1

i wondering how can i get the Content-Length size when i call kuzzle.document.search.

Any help?

Thanks

cklinx
  • 23
  • 11
  • What do you mean by Content-Length size? Do you want to get the total number of documents available? – Aschen Feb 28 '20 at 07:32
  • No, i just want how many Mb i downloaded with the search result. So i can show, for example: 1,23Mb fetched – cklinx Feb 28 '20 at 08:00
  • Ok I see, there is no way to do that for now except by directly calling the HTTP API and reading the "Content-Length" header. If you can briefly explain your use case I will propose this feature in our next product workshop – Aschen Mar 02 '20 at 02:25
  • I need it to create a sort of offline mode where the user download multimedia, maps and data. With async calls i can show how many mb i m downloading as well. – cklinx Mar 02 '20 at 12:18
  • Ok I see. I will suggest this feature in our product workshop and I will let you know. – Aschen Mar 03 '20 at 01:22

1 Answers1

1

Unfortunately the content of the Content-Length header is not directly available through the Javascript SDK.

You can either send a raw HTTP request to Kuzzle to get this header by yourself or you can approximately compute the total size of the response by hand:

let result = await sdk.document.search(...);
const contentLength = Buffer.from(JSON.stringify(result._response)).byteLength;

As I say in the comment, I will suggest this feature in our product workshop. I will keep you informed.

Aschen
  • 1,691
  • 11
  • 15