# File handler

> Receive dropped paths and pasted clipboard images in your GPUI app.

## Try it

Copy an image, click the paragraph, and paste. The example reports how many images the clipboard supplied.

[File handler example](https://gpdoc.dev/docs/plugins/behavior/file-handler/#file-handler-example)

## Install

```sh
cargo add gpdoc-plugin-file-handler
```

## Example

```rust
use gpdoc_plugin_file_handler::{FileInput, file_handler};


let files = file_handler(|_, input, _, _| match input {
    FileInput::Drop { paths, at } => {
        eprintln!("Dropped {paths:?} at {at:?}");
        true
    }
    FileInput::Paste(images) => {
        eprintln!("Pasted {} images", images.len());
        true
    }
});
let config = gpdoc::EditorConfig::builder()
    .plugin(gpdoc_plugin_paragraph::paragraph())
    .plugin(files)
    .build()
    .expect("configure editor");
```

Drop a file or paste an image to log the event. Replace the logging with your app’s import logic. For a drop, `at` is the destination document position. A paste supplies the clipboard images and the callback can read the current selection from the editor.

Return `true` when your app consumes the event. Return `false` to let other handlers try it.

## Source code

[file-handler/src/lib.rs](/source/plugins/file-handler/src/lib.rs.txt)