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 Summary
Constructors Constructor Description SlingFileUploadHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddeleteChunks(org.apache.sling.api.resource.Resource rsrc)Delete all chunks saved within a resource.org.apache.sling.api.resource.ResourcegetLastChunk(org.apache.sling.api.resource.Resource rsrc)Get the lastSlingPostConstants.NT_SLING_CHUNK_NODETYPEResource.voidsetFile(org.apache.sling.api.resource.Resource parent, RequestProperty prop, List<Modification> changes)Uses the file(s) in the request parameter for creation of new nodes.voidsetServletContext(javax.servlet.ServletContext servletContext)
-
-
-
Method Detail
-
setServletContext
public void setServletContext(javax.servlet.ServletContext servletContext)
-
deleteChunks
public void deleteChunks(org.apache.sling.api.resource.Resource rsrc) throws org.apache.sling.api.resource.PersistenceExceptionDelete 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)
Get the lastSlingPostConstants.NT_SLING_CHUNK_NODETYPEResource.- Parameters:
rsrc-ResourcecontainingSlingPostConstants.NT_SLING_CHUNK_NODETYPEResources- Returns:
- the
SlingPostConstants.NT_SLING_CHUNK_NODETYPEchunk resource.
-
setFile
public void setFile(org.apache.sling.api.resource.Resource parent, RequestProperty prop, List<Modification> changes) throws org.apache.sling.api.resource.PersistenceExceptionUses 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 thenameis '*', the filename of the uploaded file is used.- Parameters:
parent- the parent nodeprop- the assembled property infochanges- the changes- Throws:
org.apache.sling.api.resource.PersistenceException- if an error occurs
-
-