www.dextsolution.com
DEXTUPLOAD
X5
menu toggleProduct description > Compress-download (ASP Classic)

Compress-download (ASP Classic)

Starting with DEXTUploadX5 version 1.3.0.0, we support compressed downloads. Compressed downloads are downloads that combine the downloads into a single compressed file.

One thing to keep in mind is that the server is responsible for compressing files, not the ability to compress files in the DEXTUploadX5 product. DEXTUploadX5 passes the value of the vindex property to download to the server. The server selects a target to be compressed with a vindex value and generates a compressed file. When the compressed file is created, the path to download the file is returned to the client, and DEXTUploadX5 receives the download path and requests it again.

The server must have the ability to compress files, which can be implemented using multiple compression libraries, but in the case of ASP, you can also use DEXTUpload Professional, which supports both file compression and downloading. (Compression is supported only in 4.1.0.0 or later.)

Registering item to be downloaded

You must register the item to be downloaded as a virtual file.

A virtual file is a fake file that does not exist on the user's local PC and has no substance. That is, the file is not a file to be uploaded because it is a file that does not exist locally. In general, virtual files are used to keep information about already uploaded files. (An indication that the file exists on the server)

To register a virtual file, use the addVirtualFile function or the addVirtualFileList function.

  • vindex: The unique key that distinguishes a virtual file. It can be in any format, but it should not be duplicated. (Required field)
  • name: The name of the virtual file. (Required field)
  • size: The size of the virtual file, in bytes. (Required field)
  • lock: If the lock status is true, the file can not be deleted.
var dx = dx5.get(id);
// When registering individually 
dx.addVirtualFile({ vindex: "IDX0001", name: "virtual_file.txt", size: 12345 });
dx.addVirtualFile({ vindex: "IDX0002", name: "virtual_file_lock.txt", size: 45678, lock: true });
dx.addVirtualFile({ vindex: "IDX0003", name: "cosmos.jpg", size: 195779 });

// When adding at once
dx.addVirtualFileList([
  { vindex: "IDX0001", name: "virtual_file.txt", size: 12345 },
  { vindex: "IDX0002", name: "virtual_file_lock.txt", size: 45678, lock: true },
  { vindex: "IDX0003", name: "cosmos.jpg", size: 195779 }
]);

Unlike single/multiple file(s) downloads, you do not need to set the url (or downUrl) property when using Compress-download. Compress-download requires only one address that is responsible for compressing files and returning its download path. Therefore, the url (or downUrl) property that you set for each virtual file has no effect on Compress-download.

Setting the compression path

After registering virtual files, you need to set the path for compression. The compression path can only be registered once using the setCompressURL method.

The path must be a web URL that starts with a schema (http, https).

function onDX5Created(id) {
  var dx = dx5.get(id);
    
  dx.addVirtualFile({ vindex: "IDX0001", name: "virtual_file.txt", size: 12345 });
  ...
  dx.addVirtualFile({ vindex: "IDX0005", name: "cosmos (empty) 195779.jpg", size: 195779 });

  // Set the path to process the compression. 
  dx.setCompressURL("http://domain/path/compress.asp");
}
Setting button events

Once you have set up virtual files and the compression path, you can start the Compress-download using the downloadCompressed method.

<button type="button" onclick="compress('component-id');">Compress & Download</button>
<script>
function compress(id) {
  // Perform to download after compressing according to the flag value.
  // AUTO: Compress the all virtual file.
  // SELECTED: Compress the all selected virtual file.
  // CHECKED: Compress the all checked virtual file.
  dx5.get(id).downloadCompressed("AUTO");
}
</script>

It also provides automatic binding at component loading time without using complex scripts.

<button type="button" id="btn-compress-auto">Compress & Download</button>
<button type="button" id="btn-compress-selected">Compress selected & Download</button>
<button type="button" id="btn-compress-checked">Compress checked & Download</button>
<script>
  dx5.create({
    ...,
    // The compressing and downloading function automatically sets when the component is created.
    btnDownloadCompressedAuto: "btn-compress-auto", 
    btnDownloadCompressedSelected: "btn-compress-selected", 
    btnDownloadCompressedChecked: "btn-compress-checked"
  });
</script>

The automatic binding functionality is very convenient, but it may not be suitable for implementing complex functions.

Server-side processing (ASP Classic + DEXTUpload Professional)

You can use the DEXTProCompressor object in compress.asp to handle the compression operation.

When DEXTUploadX5 calls the downloadCompressed method, it creates a list string with a comma (,) character delimiter for the vindex property values and submits this value to POST form data named 'DEXTUploadX5_VIndexes'.

'DEXTUploadX5 is a POST method that sends a value (a list of vindexes) to the server named 'DEXTUploadX5_VIndexes'.
vindexes = Split(GetFormString("DEXTUploadX5_VIndexes", "", true), ",")

tempFolder = Request.ServerVariables("APPL_PHYSICAL_PATH") & "files\temp\"
defaultFolder = Request.ServerVariables("APPL_PHYSICAL_PATH") & "files\attach\"

set fs = Server.CreateObject("Scripting.FileSystemObject")

'Creates a DEXTProCompressor object for compression.
set compressor = Server.CreateObject("DEXT.DEXTProCompressor")

'Sets the compression level. Valid only for zip format compression.
'Use a value between 0 and 9. Unspecified default compression level (-1) is used.
compressor.CompLevel = -1
    
'Add the object to be compressed to the DEXTProCompressor object.
'Compressed file names should follow the filename that is added first to the object.
for i = 0 to ubound(vindexes)
    'Sets the target to open.
    if vindexes(i) = "IDX0003" then
        set file = fs.GetFile(defaultFolder & "bridge_509147.jpg")
    elseif vindexes(i) = "IDX0004" then
        set file = fs.GetFile(defaultFolder & "beach_239826.jpg")
    elseif vindexes(i) = "IDX0005" then
        set file = fs.GetFile(defaultFolder & "cosmos (empty) 195779.jpg")
    else
        set file = nothing
    end if
    if not file is nothing then
        compressor.AddFile(file.Path)
        if compressor.Count = 1 then
            'Creation path according to compressed file format
            'zip, 7z Two compression formats are supported.
            compressor.CompFileSavePath = tempFolder & GetFileNameWithoutExtension(file.Name) & ".zip"
        end if
    end if
    set file = nothing       
next
if compressor.Count > 0 then
    'Perform compression. 
    compressedPath = compressor.Compress(true)
    set file = fs.GetFile(compressedPath)
    Response.ContentType = CONTENT_TYPE_TEXTPLAIN
    Response.CharSet = UTF8_CHARSET
    Response.Clear()
    'In the real world, you should use a different way of storing, such as a session or database , in order to get the path of the compressed file from the page that needs to be actually downloaded (zip-download.asp).
    'However, the example writes the download address in the response data with the compressed file name as the query string so that DEXTUploadX5 can receive it. 
    Response.Write(GetProtocolFromURL() & "://" & GetDomainFromURL() & ":" & GetPortFromURL() & _
        "/service/zip-download.asp?name=" & Replace(Server.UrlEncode(file.Name), "+", "%20"))
    set file = nothing
else
    Response.AppendToLog("Targets for zip not found")    
    Response.Status = HTTP_FILE_NOT_FOUND_ERR
end if
        
set compressor = nothing
set fs = nothing

After compressing the target files, you need to download the compressed file. The value recorded in the response data is the server-side path (zip-download.asp) that can download the compressed download, which can be implemented in the following manner.

fileName = GetQueryString("name", "", true)
tempFolder = Request.ServerVariables("APPL_PHYSICAL_PATH") & "files\temp\"
set fs = Server.CreateObject("Scripting.FileSystemObject")
'Gets an object representing a compressed file.
set file = fs.GetFile(tempFolder & fileName)
if file is nothing then
    Response.AppendToLog("Zip file not found")    
    Response.Status = HTTP_FILE_NOT_FOUND_ERR
else        
    'Create DEXTUpload Pro FileDownload object
    set oDextpro = Server.CreateObject("DEXT.FileDownload")
    'Start downloading.
    oDextpro.Download file.Path, file.Name, true, false    
    fs.DeleteFile(file.Path)
    set oDextpro = nothing
    'Do not use Response.Write to output any other value after this.
end if    
set file = nothing
set fs = nothing
Limitations of Compress-download and Notices
  • DEXTUploadX5 supports a series of workflows for Compress-downloads, and does not have the ability to compress files on its own.
  • Compress-download has a process of compressing files on the server side. If the time required to compress a file is long, an unintended problem may occur.

    Compressing files is a task that consumes a lot of server resources (CPU, I/O), so if you have a large number of files that are large files or compressed files. Depending on the situation, it may take a long time to wait for the file compression process, which may lead to a problem of a session being disconnected or a serious problem that the service itself is stopped. Therefore, it is recommended to use the function after establishing policy for the Compress-download.

    The DEXTUploadNJ server component product used in the Java environment provides a class called CompressUtil for compression, which uses the Apache Commons Compress library. Refer to the DEXTUploadNJ product manual for details.

  • DEXTUploadX5 displays a progress window while compression is running on the server, but it does not provide its own progress window for the download process because it will switch to a single-file-download when downloading the compressed file.
  • If you perform a zip download in the macOS Safari browser, the download process may not be convenient due to the browser's pop-up blocking feature. Therefore, it is necessary to cancel the Safari setting which blocks the pop-up of the site that you want to service beforehand.

    Since the macOS Safari browser unzips the zip file by 'Open file safely' function after downloading the file, the zip file may not be downloaded as it is. If you want to prevent the zip file from being automatically unzipped, you can check the settings in the General tab of Safari Preferences.