    def _from_sample(self, sample: FileType | str) -> FileType:
        """
        Create a :class:`~bentoml._internal.io_descriptors.file.File` IO Descriptor from given inputs.

        Args:
            sample: Given File-like object, or a path to a file.
            kind: The kind of file-like object to be used. Currently, the only accepted value is ``binaryio``.
            mime_type: Optional MIME type for the descriptor. If not provided, ``from_sample``
                       will try to infer the MIME type from the file extension.

        Returns:
            :class:`~bentoml._internal.io_descriptors.file.File`: IODescriptor from given users inputs.

        Example:

        .. code-block:: python
           :caption: `service.py`

           from __future__ import annotations

           import bentoml
           from typing import Any
           from bentoml.io import File

           input_spec = File.from_sample("/path/to/file.pdf")
           @svc.api(input=input_spec, output=File())
           async def predict(input: t.IO[t.Any]) -> t.IO[t.Any]:
               return await runner.async_run(input)

        Raises:
            :class:`MissingDependencyException`: If ``filetype`` is not installed.
            ValueError: If the MIME type cannot be inferred automatically.
            :class:`BadInput`: Any other errors that may occur during the process of figure out the MIME type.
        """
        import mimetypes

        if isinstance(sample, t.IO):
            sample = FileLike[bytes](sample, "<sample>")
        elif isinstance(sample, (str, os.PathLike)):
            p = resolve_user_filepath(sample, ctx=None)
            mime = mimetypes.guess_type(p)[0]
            self._mime_type = mime
            with open(p, "rb") as f:
                sample = FileLike[bytes](f, "<sample>")
        return sample
Create a :class:`~bentoml._internal.io_descriptors.file.File` IO Descriptor from given inputs.

Args:
sample: Given File-like object, or a path to a file.
kind: The kind of file-like object to be used. Currently, the only accepted value is ``binaryio``.
mime_type: Optional MIME type for the descriptor. If not provided, ``from_sample``
will try to infer the MIME type from the file extension.

Returns:
:class:`~bentoml._internal.io_descriptors.file.File`: IODescriptor from given users inputs.

Example:

.. code-block:: python
:caption: `service.py`

from __future__ import annotations

import bentoml
from typing import Any
from bentoml.io import File

input_spec = File.from_sample("/path/to/file.pdf")
@svc.api(input=input_spec, output=File())
async def predict(input: t.IO[t.Any]) -> t.IO[t.Any]:
return await runner.async_run(input)

Raises:
:class:`MissingDependencyException`: If ``filetype`` is not installed.
ValueError: If the MIME type cannot be inferred automatically.
:class:`BadInput`: Any other errors that may occur during the process of figure out the MIME type.
src/bentoml/_internal/io_descriptors/file.py