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.
1
wire.download({
2
url: "/download-file",
3
fileName: "sales_oct.pdf"
4
});
Copied!
Add parameters to the call if needed.
1
wire.download({
2
url: "/DownloadFile?month=10",
3
fileName: "sales_oct.pdf"
4
});
Copied!
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.
1
const payload = { month: 10 };
2
3
wire.download({
4
url: "/DownloadFile",
5
data: payload,
6
fileName: "sales_oct.pdf"
7
});
Copied!
Below is a C# example of what the service method might look like for this call.
1
using Microsoft.AspNetCore.Mvc;
2
3
public class DownloadController : Controller {
4
5
[HttpGet]
6
public async Task<IActionResult> DownloadFile(int month)
7
{
8
try
9
{
10
// Get sales report data in bytes for month = 10 (October)
11
byte[] pdfFile = GetReport(month);
12
13
// Return the file to the caller
14
return File(pdfFile, "application/pdf");
15
}
16
catch (Exception ex)
17
{
18
return Json(ex);
19
}
20
}
21
}
Copied!
For a complete list of download options, visit the wire.download reference page.
Copy link