Explanation
Downloading means that the response data sent from the server is not opened in the browser or external plug-in, but is directly saved as a file to the disk when the target is requested by HTTP GET.
In general, if the target of the download is a format that the browser can not interpret, the browser will download the target as an attachment. However, if the file can be interpreted like an image file with JPG extension, the object is not downloaded but displayed through a browser window.
To download directly without opening the target, you must send a response-header (Content-Disposition: attachment) that tells the browser to force downloading, depending on the browser itself (context menu - Save As) or when sending response data from the server do.
Because DEXTUploadX5 uses the technology of the web browser, it can be opened, not downloaded. Therefore, in order to download files consistently, you must use a server file download component, such as a server or DEXTUpload.NET Pro, to set the response header so that it can be downloaded, not opened.
This example is handled by the generic handler(common-download.ashx).
# Server-side
var key = context.Request.QueryString["key"] ?? string.Empty;
var path = null as string;
if (key.Equals("FID0001")) path = "~/files/attach/bridge_509147.jpg";
else if (key.Equals("FID0002")) path = "~/files/attach/beach_239826.jpg";
else if (key.Equals("FID0003")) path = "~/files/attach/cosmos (empty) 195779.jpg";
else throw new HttpException(404, "The target not found.");
using (var dext = new DEXTUpload.NET.FileDownload())
{
dext.Download(path, new DEXTUpload.NET.DownloadOption {
AllowingWeakRange = (context.Request.UserAgent.IndexOf("DEXTUploadX5") >= 0)
});
}
// After downloading, do not write any data to the Response object.
The DEXTUploadX5 supports single file download and limited multiple file download (since version 1.1.0.0).
To download a file by using the script, use the downloadById, download function.
To download multiple files, set the value of the second parameter of the download function to true.
The downloadable target must be a virtual file that has the value of the downUrl (or url) property.
var dx = dx5.get("component id");
// The download web path must exist in the downUrl property.
dx.addVirtualFile({ ... name: "bridge_509147.jpg", downUrl: "http://.../service/common-download.do?key=FID0001" });
// Performing a single file download using the unique ID of the virtual file.
dx.downloadById("Unique ID of the virtual file to download");
// Performing a single file download based on the flag value.
// AUTO: Download the first virtual file.
// SELECTED: Download the first virtual file among the selected objects.
// CHECKED: Download the first virtual file among the checked objects.
dx.download("SELECTED");
// Performing multiple files download according to flag value.
// AUTO: Downloading all virtual files
// SELECTED: Downloading all selected virtual files
// CHECKED: Downloading all checked virtual files
dx.download("SELECTED", true);
Unlike single file download, multiple file download limits the size of downloaded files due to browser performance issues.
The default is up to 100MB. To allow more than the file size, you can use the setLimitMultiDownloadSize function to change the limited size.
However, this function changes the size of the file that is allowed to be downloaded, but does not provide the ability to download it regardless of the performance of the browser. In order to continuously download files using the function of HTML5, since the download target is temporarily loaded into the memory, a file having a large capacity such as a moving picture file is not suitable for downloading a proper multiple files. Therefore, if you need features such as downloading large amounts of data, you should use HD application.
// Set the download limit size up to 300MB. dx.setLimitMultiDownloadSize(1024 * 1024 * 300);
Example
Single file download |
|
|
|
Multiple files download |
|
(Since the browser finally stores the file (which the product can not participate in), even if the download is complete, the browser may be asking itself to query itself later, or there may be additional queries.) |