B4J Question B4J Server - How To Allow Download of Bytes with Authenticated API Call

cklester

Well-Known Member
Licensed User
I've got a B4J server set up and receiving bytes behind an API. The user must be authenticated (an auth token in the header) in order to be able to upload his files. This is working smoothly. The data is received and put in the remote secure database.

How do I then allow that data to be downloaded back to the client? What is the server-side code I need for the B4J server to send that file? I've done a search and didn't find anything about allowing a download from an authentication-required API.
 

cklester

Well-Known Member
Licensed User
I'm going to try sending the data back in Base64 encoding via JSON. Anything wrong with this approach?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. You can use a simple Filter handler to block unauthenticated requests.

2. If the file is in the www folder then you don't need to do anything. Otherwise you need to do it with:
B4X:
Dim b() As Byte = File.ReadBytes(...)
resp.OutputStream.WriteBytes(b, 0, b.Length) 'resp is the ServletResponse object.
 
Upvote 0
Top