www.dextsolution.com
DEXTUPLOAD
JK
menu toggleReference > dextuploadjk > support > spring > JKFileDownloadView

dextuploadjk.support.spring
Class JKFileDownloadView

Minimum version
1.0.0
Minimum environment
Java 17, Spring Framework 6.0.14, Spring Boot 3.0.12
Description

Concrete class of the JKAbstractDownloadableView abstract class that supports file-type responses in the Spring Framework environment.

It is used to download physical file data.

@RequestMapping(value = "download-file", method = RequestMethod.GET)
public ModelAndView download(...) {
    
  // Create a JKFileDownloadView object to download the file.
  JKFileDownloadView view = new JKFileDownloadView();
    
  view.setFile(new File("File path"));
  view.setFilename("Filename to use when downloading");
  view.setMime("text/plain");
  view.setCharsetName("UTF-8");
    
  return new ModelAndView(view);
}
Constructor

JKFileDownloadView

  • Create an object of class JKFileDownloadView.

  • Signatures

    public JKFileDownloadView()
    public JKFileDownloadView(File file)
    public JKFileDownloadView(File file, String filename)
    public JKFileDownloadView(File file, String filename, String mime)
    public JKFileDownloadView(File file, String filename, String mime, boolean inline)
    public JKFileDownloadView(File file, String filename, String mime, boolean inline, boolean useClientCache)
    public JKFileDownloadView(File file, String filename, String mime, boolean inline, boolean useClientCache, boolean removeAfterDownloading)
    public JKFileDownloadView(File file, String filename, String mime, boolean inline, boolean useClientCache, boolean removeAfterDownloading, int downloadStreamBufferSize)
    public JKFileDownloadView(File file, String filename, String mime, boolean inline, boolean useClientCache, boolean removeAfterDownloading, int downloadStreamBufferSize, long expiringTime)
    public JKFileDownloadView(File file, String filename, String mime, FileResponseContentDisposition contentDisposition, boolean useClientCache, boolean removeAfterDownloading, int downloadStreamBufferSize, long expiringTime)
    public JKFileDownloadView(File file, String filename, String mime, FileResponseContentDisposition contentDisposition, boolean useClientCache, boolean removeAfterDownloading, int downloadStreamBufferSize, long expiringTime, boolean useTomcatSendFile)
  • Parameters

    Name Type Description
    file java.io.File A File object to be downloaded
    filename java.lang.String The name of the file the client will download
    mime java.lang.String The value of the Content-Type header setting. The default value is application/octet-stream.
    inline boolean

    If the parameter value is set to true, the file will not be downloaded and can be opened directly in the browser.

    useClientCache boolean

    Whether to use client cache policy

    removeAfterDownloading boolean

    If the parameter value is true, the target file is deleted after the download operation is completed.

    downloadStreamBufferSize int

    The size of the buffer to write to the response stream at a time when downloading.

    The default value is 32768 bytes.

    expiringTime long

    A time value to set the cache expiration date.

    The default value is 31536000 seconds.

    contentDisposition dextuploadjk.engine.FileResponseContentDisposition How file content is delivered to the browser
    useTomcatSendFile (1.2.0 or later) boolean Whether to use Tomcat sendFile
Methods

getFile

  • Returns the target java.io.File object to download.

  • Signatures

    public File getFile()
  • Return

    The target java.io.File object to download

setFile

  • Sets the target java.io.File object to download.

  • Signatures

    public void setFile(File file)
  • Parameters

    Name Type Description
    file java.io.File A File object to be downloaded

isAllowingWeakRange

  • Returns whether to perform a Partial Content download using only the Range request header.

    (A partial content download means that only a portion of the data is returned in the response data.)

  • Signatures

    public boolean isAllowingWeakRange()
  • Return

    If true, only the Range header is processed; if false, the If-Range header is checked.

setAllowingWeakRange

  • Sets whether to perform a Partial Content download with only Range request headers.

    (A partial content download is when only a portion of the data is returned in the response data.)

  • Signatures

    public void setAllowingWeakRange(boolean allowingWeakRange)
  • Parameters

    Name Type Description
    allowingWeakRange boolean If true, only the Range header is processed; if false, the If-Range header is checked.

isUseClientCache

  • Returns whether the client cache is enabled or disabled.

  • Signatures

    public boolean isUseClientCache()
  • Return

    If true, the cache policy is enabled; if false, it is disabled.

setUseClientCache

  • Set whether to use the client cache.

    For stream downloads, the cache policy is not used even if set to true.

  • Signatures

    public void setUseClientCache(boolean useClientCache)
  • Parameters

    Name Type Description
    useClientCache boolean If true, the cache policy is enabled; if false, it is disabled.

isRemoveAfterDownloading

  • Returns whether to delete the target file after downloading the file.

  • Signatures

    public boolean isRemoveAfterDownloading()
  • Return

    true, false

setRemoveAfterDownloading

  • Sets whether to delete the target file after downloading the file.

    The file deletion feature only works when the entire file is downloaded as an attachment, and file deletion may fail if the target file is preempted by another system.

  • Signatures

    public void setRemoveAfterDownloading(boolean removeAfterDownloading)
  • Parameters

    Name Type Description
    removeAfterDownloading boolean Set to true to delete the file.

getExpiringTime

  • Returns the time value required to set the Cache Expired response header.

  • Signatures

    public long getExpiringTime()
  • Return

    Time value in seconds to set the cache expiration response header

setExpiringTime

  • Sets the time value required to set the Cache Expired response header.

  • Signatures

    public void setExpiringTime(long time)
  • Parameters

    Name Type Description
    time long Setting value in seconds

getUseTomcatSendFile (supported from version 1.2.0)

  • Returns whether Tomcat sendFile is used for file downloads.

  • Signatures

    public boolean getUseTomcatSendFile()
  • Return

    true or false. The default value is false.

setUseTomcatSendFile (supported from version 1.2.0)

  • Sets whether Tomcat sendFile is used for file downloads.

    (Caution) This setting cannot be used when HTTP compression is enabled or when response data is controlled through a servlet filter. If an error occurs, set this value to false to use the default download method.

  • Signatures

    public void setUseTomcatSendFile(boolean useTomatSendFile)
  • Parameters

    Name Type Description
    useTomatSendFile boolean true to use sendFile; otherwise false

doRenderImpl

See the doRenderImpl method of the JKAbstractDownloadableView abstract class.

getFilename

See the getFilename method of the JKAbstractDownloadableView abstract class.

setFilename

See the setFilename method of the JKAbstractDownloadableView abstract class.

getMime

See the getMime method of the JKAbstractDownloadableView abstract class.

setMime

See the setMime method of the JKAbstractDownloadableView abstract class.

isInline

See the isInline method of the JKAbstractDownloadableView abstract class.

setInline

See the setInline method of the JKAbstractDownloadableView abstract class.

getCharsetName

See the getCharsetName method of the JKAbstractDownloadableView abstract class.

setCharsetName

See the setCharsetName method of the JKAbstractDownloadableView abstract class.

getDownloadStreamBufferSize

See the getDownloadStreamBufferSize method of the JKAbstractDownloadableView abstract class.

setDownloadStreamBufferSize

See the setDownloadStreamBufferSize method of the JKAbstractDownloadableView abstract class.

getContentDisposition

See the getContentDisposition method of the JKAbstractDownloadableView abstract class.

setContentDisposition

See the setContentDisposition method of the JKAbstractDownloadableView abstract class.