WireBootstrap
HomeDocsBuySupport
  • Introduction
  • Overview
  • Getting Started
  • Installation
  • Connecting to Data
    • Data Connectors
      • SQL Data
      • Custom Web Services
      • Local Data
      • Other Sources
    • Data Sources
    • Discovery
    • Building a Data Connector
  • Working With Queries
    • Select Queries
      • Query Extensions
    • Stored Procedures
    • Custom Web Services
    • Executing Queries
    • ORM
  • Writing Data
  • Updates
  • Deletes
  • Working with DataTables
    • Introduction
    • Filter and Sort
    • Select and Calculate
    • Joins
    • Rows
    • Columns
  • Working with DataSets
  • Introduction
  • Executing Queries
  • Transforms
  • Writing Data
  • Data Events
  • Working with Components
    • Introduction
    • Encapsulation
    • Configuration
      • Data
      • Events
      • Observables
      • Validation
      • Display
      • Vendor
      • Custom
    • Component
    • Web Frameworks
    • Building a Component
      • Hello World
      • Data Events
      • DataSets
  • Working With Data Events
    • Introduction
    • Event Basics
    • Event Data
    • Event Actions
  • Working with Themes
    • Introduction
    • Sample Data
    • Libraries
    • Pages
    • Building a Theme Project
  • Utilities
    • Formatting
    • Expressions
    • Collections
    • Spinners
    • Copy and Merge
    • Validation
    • Loading Assets
    • Service Calls
    • Download Files
    • Browser Location
    • Types
    • Promise
  • Reference
    • wire
      • wire.Collection
      • wire.download
      • wire.validate
    • wire.data
      • wire.data.DataEvent
      • wire.data.DataModel
      • wire.data.DataPromise
      • wire.data.DataSet
      • wire.data.DataSource
      • wire.data.DataTable
        • Columns
        • Rows
      • wire.data.StoredProcedure
      • wire.data.TableQuery
    • wire.ui
      • wire.ui.Component
      • wire.ui.validate
Powered by GitBook
On this page

Was this helpful?

  1. Utilities

Download Files

WireBootstrap 's wire.download functions handles all the internal details needed to support downloading files from an API call.

The following example makes an HTTP GET call to download a file from a data service at the location specified in the url property in the configuration. The downloaded file name is specified using the fileName property.

wire.download({
    url: "/download-file",
    fileName: "sales_oct.pdf"
});

Add parameters to the call if needed.

wire.download({
    url: "/DownloadFile?month=10",
    fileName: "sales_oct.pdf"
});

To change the call to a POST call in order to send data to the data service in the body of the request before the file is downloaded, add the data property in the configuration and include the data as seen below.

const payload = { month: 10 };

wire.download({
    url: "/DownloadFile",
    data: payload,    
    fileName: "sales_oct.pdf"
});

Below is a C# example of what the service method might look like for this call.

using Microsoft.AspNetCore.Mvc;

public class DownloadController : Controller {

    [HttpGet]
    public async Task<IActionResult> DownloadFile(int month)
    {
        try
        {            
            // Get sales report data in bytes for month = 10 (October)        
            byte[] pdfFile = GetReport(month);
               
            // Return the file to the caller
            return File(pdfFile, "application/pdf");            
        }
        catch (Exception ex)
        {
            return Json(ex);
        }
    }
}
PreviousService CallsNextBrowser Location

Last updated 3 years ago

Was this helpful?

For a complete list of download options, visit the reference page.

wire.download