NetTalk Central
NetTalk Web Server => Web Server - Ask For Help => Topic started by: Niels Larsen 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:
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
-
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
-
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
-
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?
-
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?
-
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
-
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.
-
Hi Bruce
I followed your advice to play with example 40 "ServeDocument" and it's just perfect - works exactly as it should.
Thanks!