Skip to main content

Providing File Downloads

File Download via REST Web Services​

REST web services can deliver binary content as downloadable files. This enables integration scenarios like document export, report delivery, or file archive access.

Requirements​

To enable file download:

  • The response must include binary content.
  • Set response.isBase64 to true to indicate Base64 encoding.
  • Use the Content-Disposition header to control download behavior.

Example Implementation​

import { db, logging } from "@aditosoftware/jdito-types";

function restget(pRequestAsJson) {
// Parse incoming request
pRequestAsJson = JSON.parse(pRequestAsJson);

// Example file ID (stored in ASYS_BINARIES)
const fileId = "20350d7f-bce7-4902-8a89-43db0ffc117a";

// Load binary content from database
const fileContent = db.getBinaryContent(fileId, "AO_DATEN");

// Set response body to binary data
pRequestAsJson.response.body = fileContent;

// Enable Base64 encoding for response
pRequestAsJson.response.isBase64 = true;

// Set HTTP headers to define download behavior
pRequestAsJson.response.header = {
"Content-Disposition": "inline; filename=example.txt",
"content-type": "text/plain"
};

return JSON.stringify(pRequestAsJson);
}
note

Use attachment in the Content-Disposition header to enforce file download instead of inline display.