Interface DownloadService

All Known Implementing Classes:
DownloadServiceImpl

public interface DownloadService
This service allows the download of blobs to a HTTP response.
Since:
7.3
  • Field Details

    • EVENT_NAME

      static final String EVENT_NAME
      See Also:
    • NXFILE

      static final String NXFILE
      See Also:
    • NXDOWNLOADINFO

      static final String NXDOWNLOADINFO
      See Also:
    • NXBIGBLOB

      static final String NXBIGBLOB
      See Also:
    • BLOBHOLDER_PREFIX

      static final String BLOBHOLDER_PREFIX
      See Also:
    • BLOBHOLDER_0

      static final String BLOBHOLDER_0
      See Also:
    • TRANSIENT_STORE_PARAM_ERROR

      static final String TRANSIENT_STORE_PARAM_ERROR
      The transient store parameter name for storing an error if any. Stored entry must
      See Also:
    • TRANSIENT_STORE_PARAM_PROGRESS

      static final String TRANSIENT_STORE_PARAM_PROGRESS
      See Also:
    • TRANSIENT_STORE_STORE_NAME

      static final String TRANSIENT_STORE_STORE_NAME
      See Also:
    • EXTENDED_INFO_RENDITION

      static final String EXTENDED_INFO_RENDITION
      The extended info containing the rendition name.
      Since:
      11.1
      See Also:
    • EXTENDED_INFO_CLIENT_REASON

      static final String EXTENDED_INFO_CLIENT_REASON
      The extended info containing the client reason.
      Since:
      2023.0
      See Also:
    • REQUEST_ATTR_DOWNLOAD_REASON

      static final String REQUEST_ATTR_DOWNLOAD_REASON
      Internal request attribute recording the reason to use for the download.
      Since:
      11.1
      See Also:
    • REQUEST_ATTR_DOWNLOAD_RENDITION

      static final String REQUEST_ATTR_DOWNLOAD_RENDITION
      Internal request attribute recording the rendition triggering the download.
      Since:
      11.1
      See Also:
    • REQUEST_QUERY_PARAM_CLIENT_REASON

      static final String REQUEST_QUERY_PARAM_CLIENT_REASON
      Public request query parameter recording the client reason to use for the download.
      Since:
      2023.0
      See Also:
    • REQUEST_HEADER_CLIENT_REASON

      static final String REQUEST_HEADER_CLIENT_REASON
      Public request header recording the client reason to use for the download.
      Since:
      2023.0
      See Also:
  • Method Details

    • storeBlobs

      String storeBlobs(List<Blob> blobs)
      Stores the blobs for later download.
      Parameters:
      blobs - the list of blobs to store
      Returns:
      the store key used for retrieving the blobs (@see getDownloadUrl(String)
      Since:
      9.1
    • getFullDownloadUrl

      String getFullDownloadUrl(DocumentModel doc, String xpath, Blob blob, String baseUrl)
      Gets the full download URL (after redirects if configured so) for the given blob.
      Parameters:
      doc - the document
      xpath - the blob's xpath or blobholder index, or null for default
      blob - the blob
      baseUrl - the base URL to use for Nuxeo downloads (if there is no redirect)
      Returns:
      the full URL (which may be to a redirected server)
      Since:
      11.1
      Implementation Requirements:
      Configuration to follow redirects is done through the org.nuxeo.download.url.follow.redirect configuration property.
    • getDownloadUrl

      String getDownloadUrl(DocumentModel doc, String xpath, String filename)
      Gets the URL to use to download the blob at the given xpath in the given document.

      The URL is relative to the Nuxeo Web Application context.

      Returns something like nxfile/reponame/docuuid/blobholder:0/foo.jpg?changeToken=5-1

      Parameters:
      doc - the document
      xpath - the blob's xpath or blobholder index, or null for default
      filename - the blob's filename, or null for default
      Returns:
      the download URL with changeToken as query param for optimized http caching
    • getDownloadUrl

      String getDownloadUrl(String repositoryName, String docId, String xpath, String filename, String changeToken)
      Gets the URL to use to download the blob at the given xpath in the given document.

      The URL is relative to the Nuxeo Web Application context.

      Returns something like nxfile/reponame/docuuid/blobholder:0/foo.jpg?changeToken=5-1

      Parameters:
      repositoryName - the document repository
      docId - the document id
      xpath - the blob's xpath or blobholder index, or null for default
      filename - the blob's filename, or null for default
      changeToken - the doc changeToken which will be appended as a query parameter for optimized http caching.
      Returns:
      the download URL
      Since:
      10.3
    • getDownloadUrl

      String getDownloadUrl(String repositoryName, String docId, String xpath, String filename)
      Gets the URL to use to download the blob at the given xpath in the given document.

      The URL is relative to the Nuxeo Web Application context.

      Returns something like nxfile/reponame/docuuid/blobholder:0/foo.jpg

      Parameters:
      repositoryName - the document repository
      docId - the document id
      xpath - the blob's xpath or blobholder index, or null for default
      filename - the blob's filename, or null for default
      Returns:
      the download URL
    • getDownloadUrl

      String getDownloadUrl(String storeKey)
      Gets the URL to use to download the blobs identified by a storage key.

      The URL is relative to the Nuxeo Web Application context.

      Returns something like nxbigblob/key

      Parameters:
      storeKey - The key of stored blobs to download
      Returns:
      the download URL
      Since:
      9.1
    • resolveBlobFromDownloadUrl

      Blob resolveBlobFromDownloadUrl(String downloadURL)
      Finds a document's blob given the download URL returned by getDownloadUrl(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, java.lang.String).

      The permissions are check whether the user can download the blob or not.

      Parameters:
      downloadURL - the URL to use to download the blob
      Returns:
      the blob, or null if not found or if the user has no permission to download it
      Since:
      9.1
    • handleDownload

      void handleDownload(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse resp, String baseUrl, String path) throws IOException
      Handles the download of a document.
      Parameters:
      req - the request
      resp - the response
      baseUrl - the request baseUrl
      path - the request path, without the context
      Throws:
      IOException
      Since:
      9.1
    • downloadBlob

      void downloadBlob(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, String storeKey, String reason) throws IOException
      Triggers a blobs download. Once the temporary blobs are transfered from the store, they are automatically deleted. The returned HTTP Status Code is 200 if the blob is ready or 202 if it is still being processed.
      Parameters:
      storeKey - the stored blobs key
      reason - the download reason
      Throws:
      IOException
      Since:
      9.1
    • downloadBlob

      @Deprecated void downloadBlob(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason) throws IOException
      Deprecated.
      since 11.1, use downloadBlob(DownloadContext) instead
      Triggers a blob download.
      Parameters:
      doc - the document, if available
      xpath - the blob's xpath or blobholder index, if available
      blob - the blob, if already fetched
      filename - the filename to use
      reason - the download reason
      Throws:
      IOException
    • downloadBlob

      @Deprecated void downloadBlob(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason, Map<String,Serializable> extendedInfos) throws IOException
      Deprecated.
      since 11.1, use downloadBlob(DownloadContext) instead
      Triggers a blob download.
      Parameters:
      doc - the document, if available
      xpath - the blob's xpath or blobholder index, if available
      blob - the blob, if already fetched
      filename - the filename to use
      reason - the download reason
      extendedInfos - an optional map of extended informations to log
      Throws:
      IOException
    • downloadBlob

      @Deprecated void downloadBlob(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason, Map<String,Serializable> extendedInfos, Boolean inline) throws IOException
      Deprecated.
      since 11.1, use downloadBlob(DownloadContext) instead
      Triggers a blob download.
      Parameters:
      doc - the document, if available
      xpath - the blob's xpath or blobholder index, if available
      blob - the blob, if already fetched
      filename - the filename to use
      reason - the download reason
      extendedInfos - an optional map of extended informations to log
      inline - if not null, force the inline flag for content-disposition
      Throws:
      IOException
    • downloadBlob

      @Deprecated void downloadBlob(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, DocumentModel doc, String xpath, Blob blob, String filename, String reason, Map<String,Serializable> extendedInfos, Boolean inline, Consumer<ByteRange> blobTransferer) throws IOException
      Deprecated.
      since 11.1, use downloadBlob(DownloadContext) instead
      Triggers a blob download.
      Parameters:
      doc - the document, if available
      xpath - the blob's xpath or blobholder index, if available
      blob - the blob, if already fetched
      filename - the filename to use
      reason - the download reason
      extendedInfos - an optional map of extended informations to log
      inline - if not null, force the inline flag for content-disposition
      blobTransferer - the transferer of the actual blob
      Throws:
      IOException
      Since:
      7.10
    • downloadBlob

      void downloadBlob(DownloadService.DownloadContext context) throws IOException
      Triggers a blob download.
      Parameters:
      context - the download context
      Throws:
      IOException
      Since:
      11.1
    • transferBlobWithByteRange

      void transferBlobWithByteRange(Blob blob, ByteRange byteRange, Supplier<OutputStream> outputStreamSupplier)
      Copies the blob stream at the given byte range into the supplied OutputStream.
      Parameters:
      blob - the blob
      byteRange - the byte range
      outputStreamSupplier - the OutputStream supplier
      Since:
      7.10
    • logDownload

      @Deprecated default void logDownload(DocumentModel doc, String blobXPath, String filename, String reason, Map<String,Serializable> extendedInfos)
      Deprecated.
      since 11.1, use the signature including the request
      Logs a download.
      Parameters:
      doc - the doc for which this download occurs, if available
      blobXPath - the blob's xpath or blobholder index, if available
      filename - the filename
      reason - the download reason
      extendedInfos - an optional map of extended informations to log
    • logDownload

      void logDownload(jakarta.servlet.http.HttpServletRequest request, DocumentModel doc, String blobXPath, String filename, String reason, Map<String,Serializable> extendedInfos)
      Logs a download.
      Parameters:
      request - the HTTP request, if available
      doc - the doc for which this download occurs, if available
      blobXPath - the blob's xpath or blobholder index, if available
      filename - the filename
      reason - the download reason
      extendedInfos - an optional map of extended informations to log
      Since:
      11.1
    • resolveBlob

      Blob resolveBlob(DocumentModel doc, String xpath)
      Finds a document's blob given an xpath or blobholder index
      Parameters:
      doc - the document
      xpath - the xpath or blobholder index
      Returns:
      the blob, or null if not found
    • resolveBlob

      Blob resolveBlob(DocumentModel doc)
      Finds a document's blob.
      Parameters:
      doc - the document
      Returns:
      the blob, or null if not available
      Since:
      9.3
    • checkPermission

      boolean checkPermission(DocumentModel doc, String xpath, Blob blob, String reason, Map<String,Serializable> extendedInfos)
      Checks whether the download of the blob is allowed.
      Parameters:
      doc - the doc for which this download occurs, if available
      xpath - the blob's xpath or blobholder index, if available
      blob - the blob
      reason - the download reason
      extendedInfos - an optional map of extended informations to log
      Returns:
      true if download is allowed
      Since:
      7.10