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 DEXTUploadNJ, to set the response header so that it can be downloaded, not opened.
This example is handled by the servlet(CommonFileDownload class) for file download processing and is mapped to common-download.do in web.xml.
# Server-side
File target = null;
String key = request.getParameter("key");
if (key.equals("FID0001")) target = new File(fileRoot, "bridge_509147.jpg");
else if (key.equals("FID0002")) target = new File(fileRoot, "beach_239826.jpg");
else if (key.equals("FID0003")) target = new File(fileRoot, "cosmos (empty) 195779.jpg");
if (target == null || target.exists() == false || target.isFile() == false) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, "File not found.");
return;
}
try {
// Creating a FileDownload object.
FileDownload dextnj = new FileDownload();
// Setting the encoding to UTF-8.
response.setCharacterEncoding("UTF-8");
// Downloading the file as an attachment file. (Content-Disposition: attachment ...)
dextnj.download(request, response, target);
} catch (Exception e) {
throw new ServletException(e);
}
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 only changes the size of the files that are allowed to be downloaded, not the ability to allow downloads to occur regardless of the browser's performance. Because downloading files continuously using HTML5's features temporarily loads the download target into memory, large files, such as video files, are not good candidates for multi-file downloads. Therefore, if you need features such as large downloads and continuation, HD applications are recommended.
// 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.) |