Services

FilePicker

FilePicker service

Create or retrieve this service with page.file_picker(**properties). Ruflet reuses the registered service unless you supply a different id.

Example

selected = text(value: "No files selected")
page.add(selected)
page.pick_files(
  allow_multiple: true,
  file_type: "image",
  on_result: ->(files, error) {
    names = Array(files).map { |file| file["name"] || file[:name] }
    page.update(selected, value: error ? error.to_s : names.join(", "))
  }
)

Page accessor

  • page.file_picker(**props)

Properties

  • data — Arbitrary value you can attach to the control and read back in handlers.
  • key — Stable identity used to preserve state across rebuilds.

Events

  • on_result — Fired on result.
  • on_upload — Fired on upload.

Page convenience methods

Use these one-shot Page calls when you do not need to keep the service object:

  • page.pick_files(dialog_title: ..., initial_directory: ..., file_type: ..., allowed_extensions: ..., allow_multiple: ..., with_data: ..., timeout: ..., on_result: ...)
  • page.save_file(dialog_title: ..., file_name: ..., initial_directory: ..., file_type: ..., allowed_extensions: ..., src_bytes: ..., timeout: ..., on_result: ...)
  • page.get_directory_path(dialog_title: ..., initial_directory: ..., timeout: ..., on_result: ...)
  • page.upload(files, timeout: ..., on_result: ...)
  • page.upload_files(files, timeout: ..., on_result: ...)

Result and error handling

Client calls are asynchronous. When a method accepts on_result:, handle both callback values: |result, error|. Availability and returned data can vary by platform.

Common service API

The service also supports the common Ruflet control API: attach_handler(event_name, handler), children, emit(event_name, event), has_handler?(event_name), id, merge_props(values = ...), on(event_name, &block), props, runtime_page, runtime_page=, to_patch, type, wire_id, wire_id=.

Use the named methods above for application code; common control methods mainly support event registration, updates, and runtime integration.

Wire reference

  • Service helper: file_picker
  • Wire type: filepicker
  • Aliases: filepicker