Files & Documents
Commands that trigger file downloads or open document previews.
Download
Trigger a file download in the user's browser.
When to use: Downloading reports, documents, exports, or any generated file from the server.
JSON Response:
{
"feCommand": {
"Download": {
"outFileName": "Monthly_Report.pdf",
"filePath": "/path/to/file/report.pdf"
}
}
}
- C# / .NET
- PHP
if (string.Equals(widgetName, "DOWNLOADBTN"))
{
string filePath = await GetFileFromStorage("report.pdf");
response.Set("FECommand", new Dictionary<string, object>
{
["Download"] = new
{
outFileName = "Monthly_Report.pdf",
filePath = filePath
}
});
}
// Stream the file if Download command is set
var feCommands = response.Get()["feCommand"] as Dictionary<string, object>;
if (feCommands != null && feCommands.ContainsKey("Download"))
{
var downloadData = feCommands["Download"] as dynamic;
string outFileName = downloadData.outFileName;
string filePath = downloadData.filePath;
if (System.IO.File.Exists(filePath))
{
S3FileStorageService s3 = (S3FileStorageService)_pluginServiceProvider.GetFileStorageProvider();
Response.ContentType = S3FileStorageService.GetMimeType(outFileName);
Response.Headers.Add("Content-Disposition", $"attachment; filename*=UTF-8''{Uri.EscapeDataString(outFileName)}");
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
await s3.WriteFileInChunks(Response.Body, fs);
}
System.IO.File.Delete(filePath);
return new EmptyResult();
}
}
response.Set(HandlerResponse.FormData, request.FormData);
return Ok(await response.Get());
if ($widgetName === 'DOWNLOADBTN') {
$filePath = $this->getFileFromStorage('report.pdf');
$response['feCommand']['Download'] = [
'outFileName' => 'Monthly_Report.pdf',
'filePath' => $filePath
];
}
if (!empty($response['feCommand']['Download'])) {
$download = $response['feCommand']['Download'];
$fileName = $download['outFileName'];
$filePath = $download['filePath'];
if (file_exists($filePath)) {
$fileResponse = response()->file($filePath, [
'Content-Type' => $this->getMimeType($fileName),
'Content-Disposition' => 'attachment; filename="' . $fileName . '"'
]);
$fileResponse->deleteFileAfterSend(true);
return $fileResponse;
}
}
$response['data'] = $request->all();
return response()->json($response);
Parameters:
outFileName(string) - The filename shown to the user when downloadingfilePath(string) - Server path to the file
PreviewDocument
Open a document preview modal.
When to use: Previewing PDFs, images, or other documents from file upload fields.
JSON Response:
{
"feCommand": {
"PreviewDocument": {
"context": null,
"fileId": "document-123.pdf",
"data": "JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlL...",
"fieldName": "documentField",
"format": "pdf"
}
}
}
- C# / .NET
- PHP
if (string.Equals(widgetName, "PREVIEWBTN"))
{
string fileId = "document-123.pdf";
string base64Data = GetBase64FileContent(fileId);
response.Set("FECommand", new Dictionary<string, object>
{
["PreviewDocument"] = new
{
context = (object)null,
fileId = fileId,
data = base64Data,
fieldName = "documentField",
format = "pdf"
}
});
}
response.Set(HandlerResponse.FormData, request.FormData);
if ($widgetName === 'PREVIEWBTN') {
$fileId = 'document-123.pdf';
$base64Data = $this->getBase64FileContent($fileId);
$response['feCommand']['PreviewDocument'] = [
'context' => null,
'fileId' => $fileId,
'data' => $base64Data,
'fieldName' => 'documentField',
'format' => 'pdf'
];
}
$response['data'] = $request->all();
Parameters:
context(object|null) - Optional context objectfileId(string) - File identifierdata(string|null) - Base64 encoded file contentfieldName(string) - Name of the field containing the fileformat(string) - File format (default:"pdf")
info
Large files (.dwg, .ifc, .rvt, .rfa, .nwd, .nwc, .nwf) do not include base64 data — data is null for these types.