# `PgLargeObjects.UploadWriter`
[🔗](https://github.com/frerich/pg_large_objects/blob/main/lib/pg_large_objects/upload_writer.ex#L2)

LiveView UploadWriter streaming data to Postgres large object.

This module can be used with `Phoenix.LiveView.allow_upload/3` to specify
that file uploads by clients should be streamed straight to large objects in
the database. Pass the `:repo` option in the second element of the tuple
returned by the function passed to `:writer` to indicate which database the
object should be created in, e.g.:

```elixir
socket
|> allow_upload(:photo,
  accept: :any,
  writer: fn _name, _entry, _socket ->
    {PgLargeObjects.UploadWriter, repo: MyApp.Repo}
  end
)
```

The object ID of the uploaded file is available in the meta data available
to the callback given to `Phoenix.LiveView.consume_uploaded_entries/3`:

```elixir
consume_uploaded_entries(socket, :photo, fn meta, _entry ->
  %{object_id: object_id} = meta

  # Store `object_id` in database to retain handle to uploaded data.

  {:ok, nil}
end)
```

See `Phoenix.LiveView.UploadWriter` for further information.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
