Class SlingFileUploadHandler

java.lang.Object
org.apache.sling.servlets.post.impl.helper.SlingFileUploadHandler

public class SlingFileUploadHandler extends Object
Handles file uploads.

Simple example: <form action="/home/admin" method="POST" enctype="multipart/form-data"> <input type="file" name="./portrait" /> </form> this will create a nt:file node below "/home/admin" if the node type of "admin" is (derived from) nt:folder, a nt:resource node otherwise.

Filename example: <form action="/home/admin" method="POST" enctype="multipart/form-data"> <input type="file" name="./*" /> </form> same as above, but uses the filename of the uploaded file as name for the new node.

Type hint example: <form action="/home/admin" method="POST" enctype="multipart/form-data"> <input type="file" name="./portrait" /> <input type="hidden" name="./portrait@TypeHint" value="my:file" /> </form> this will create a new node with the type my:file below admin. if the hinted type extends from nt:file an intermediate file node is created otherwise directly a resource node.

  • Constructor Details

    • SlingFileUploadHandler

      public SlingFileUploadHandler()
  • Method Details

    • setServletContext

      public void setServletContext(jakarta.servlet.ServletContext servletContext)
    • deleteChunks

      public void deleteChunks(org.apache.sling.api.resource.Resource rsrc) throws org.apache.sling.api.resource.PersistenceException
      Delete all chunks saved within a resource. If no chunks exist, it is no-op.
      Parameters:
      rsrc - the resource
      Throws:
      org.apache.sling.api.resource.PersistenceException - in case of problems
    • getLastChunk

      public org.apache.sling.api.resource.Resource getLastChunk(org.apache.sling.api.resource.Resource rsrc)
      Parameters:
      rsrc - Resource containing SlingPostConstants.NT_SLING_CHUNK_NODETYPE Resources
      Returns:
      the SlingPostConstants.NT_SLING_CHUNK_NODETYPE chunk resource.
    • setFile

      public void setFile(org.apache.sling.api.resource.Resource parent, RequestProperty prop, List<Modification> changes) throws org.apache.sling.api.resource.PersistenceException
      Uses the file(s) in the request parameter for creation of new nodes. if the parent node is a nt:folder a new nt:file is created. otherwise just a nt:resource. if the name is '*', the filename of the uploaded file is used.
      Parameters:
      parent - the parent node
      prop - the assembled property info
      changes - the changes
      Throws:
      org.apache.sling.api.resource.PersistenceException - if an error occurs