NetTalk Central

Author Topic: Api endpoint stream - how?  (Read 2710 times)

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
    • Email
Api endpoint stream - how?
« on: May 18, 2025, 10:34:25 PM »
Hi
I am developing an endpoint where I have to stream a pdf file (actually I have it as BASE64).
But I need some help to get going with the stream itself.
This is what I have from the associated Swagger:
Code: [Select]
  stream:
    type: object
    properties:
      canRead:
        type: boolean
      canWrite:
        type: boolean
      canSeek:
        type: boolean
      canTimeout:
        type: boolean
      length:
        format: int64
        type: integer
      position:
        format: int64
        type: integer
      readTimeout:
        format: int32
        type: integer
      writeTimeout:
        format: int32
        type: integer

Can one of you wise heads help me out?

Regards Niels

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11310
    • View Profile
Re: Api endpoint stream - how?
« Reply #1 on: May 19, 2025, 07:20:40 PM »
Can you define a bit more what you mean by "stream" a PDF file?
Tell us a bit more abut the context for this, and how "streaming" would be different from the normal "serving" ?

cheers
Bruce

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
    • Email
Re: Api endpoint stream - how?
« Reply #2 on: May 22, 2025, 12:16:50 AM »
I can see that it doesn't really make sense.
I'll try to make it a little clearer.
I have some static ftp files that I need to expose via a REST api.
I'm aware that I can BASE64 encode them but the client would prefer them as "files". This is where I'm a bit confused how to.

/Niels

urayoan

  • Full Member
  • ***
  • Posts: 223
    • View Profile
    • AZ Rock Radio
Re: Api endpoint stream - how?
« Reply #3 on: May 22, 2025, 04:47:30 AM »
Hi Neil

And why not read the file, convert to base64 for transfer purposes and then decode and save it in the format the client want?

Alberto

  • Hero Member
  • *****
  • Posts: 1887
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: Api endpoint stream - how?
« Reply #4 on: May 22, 2025, 05:04:27 AM »
Hi, May be copy your ftp files to a folder inside your web folder and create an API method to provide the ftp file link?
-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11310
    • View Profile
Re: Api endpoint stream - how?
« Reply #5 on: May 22, 2025, 07:01:32 PM »
Hi Niels,

>> I have some static ftp files that I need to expose via a REST api.

are you over thinking this?
It sounds to me like you just put the static file in the web folder (or sub folder), then the client can just GET it (ie use a regular WebClient to Fetch the file.)

I'm not sure this needs to be in an API?

But assuming it does need to be an API;

Add a StringTheory object to the RETURNS tab of the API.
Put your file in there (probably Base64 encoded.)

>> I'm aware that I can BASE64 encode them but the client would prefer them as "files".

Hence my suggestion above that this is just a regular GET.
If you want more control, then check out the FileDownload (40) example. That has a generic "ServeDocument" procedure in the app for serving files.

An API method will return a JSON or XML response - and of course any binary in there would need to be appropriately encoded at the very least for Json or XML.
I recommend Base64 because that's easier.

Cheers
Bruce




Cheers
Bruce


Niels Larsen

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
    • Email
Re: Api endpoint stream - how?
« Reply #6 on: May 22, 2025, 11:58:44 PM »
Thanks for all your input.
Now I have a bit to work with.
I can see that in my case it is by far the easiest to use BASE64 encoded.

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 459
    • View Profile
    • Email
Re: Api endpoint stream - how?
« Reply #7 on: May 26, 2025, 11:27:34 PM »
Hi Bruce

I followed your advice to play with example 40 "ServeDocument" and it's just perfect - works exactly as it should.

Thanks!