Class PasteFileHandler
java.lang.Object
com.vaadin.flow.component.clipboard.PasteFileHandler
Factory for paste-aware
UploadHandlers that group the parallel fetch
uploads of a single paste gesture and surface the result to application code.
Two flavours are offered, both producing an UploadHandler suitable
for
Clipboard.onFilePaste:
inMemory(SerializableConsumer)— a single per-file callback that receives every file as aPasteFile, withPasteFile.newPaste()flagging the first file of each paste.session()— a three-step session listener:onStartfires once per paste with the declared file count,onFilefires per file, andonCompletefires once after the last file has been delivered.
onStart / onFile / onComplete
lifecycle. Sessions live in memory until they receive all the files the
browser declared in Clipboard.PASTE_FILE_COUNT_HEADER; a paste whose
upload fails mid-flight stays open indefinitely (rare in practice, since
uploads are small, but worth knowing if an application keeps a process alive
for months).
Application code that wants "show the latest paste only" semantics tracks the highest paste id seen and filters in its own callbacks — the handler does not drop any files on the application's behalf, so a slow tail upload from an earlier paste still arrives at the listener.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classFluent builder for the session-style paste handler. -
Method Summary
Modifier and TypeMethodDescriptionstatic UploadHandlerinMemory(SerializableConsumer<PasteFile> consumer) Builds anUploadHandlerthat reads each upload fully into memory, packages it as aPasteFile, and delivers it to the supplied consumer on the UI thread.session()Starts a session-style handler builder that emitsonStartonce per paste before any file,onFileper file, andonCompleteonce the paste's declared file count has been delivered.
-
Method Details
-
inMemory
Builds anUploadHandlerthat reads each upload fully into memory, packages it as aPasteFile, and delivers it to the supplied consumer on the UI thread.- Parameters:
consumer- invoked for each accepted file on the UI thread, notnull- Returns:
- an upload handler suitable for
Clipboard.onFilePaste
-
session
Starts a session-style handler builder that emitsonStartonce per paste before any file,onFileper file, andonCompleteonce the paste's declared file count has been delivered. Any callback may be omitted.- Returns:
- a fresh, unconfigured session builder
-