Package org.apache.sling.servlets.post.impl.helper

# Klasse 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.

## Konstruktorübersicht

Konstruktoren
Konstruktor
Beschreibung
`SlingFileUploadHandler()`

## Methodenübersicht

Modifizierer und Typ
Methode
Beschreibung
`void`
`deleteChunks(org.apache.sling.api.resource.Resource rsrc)`
Delete all chunks saved within a resource.
`org.apache.sling.api.resource.Resource`
`getLastChunk(org.apache.sling.api.resource.Resource rsrc)`
Get the last `SlingPostConstants.NT_SLING_CHUNK_NODETYPE` `Resource`.
`void`
`setFile(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.
`void`
`setServletContext(jakarta.servlet.ServletContext servletContext)`

### Von Klasse geerbte Methoden java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Konstruktordetails

### SlingFileUploadHandler

public SlingFileUploadHandler()

## Methodendetails

### 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.

Parameter:
  `rsrc` - the resource
Löst aus:
  `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 last `SlingPostConstants.NT_SLING_CHUNK_NODETYPE` `Resource`.

Parameter:
  `rsrc` - `Resource` containing `SlingPostConstants.NT_SLING_CHUNK_NODETYPE` `Resource`s
Gibt zurück:
  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.

Parameter:
  `parent` - the parent node
  `prop` - the assembled property info
  `changes` - the changes
Löst aus:
  `org.apache.sling.api.resource.PersistenceException` - if an error occurs