> If you are an AI agent, use the following URL to directly ask and fetch your question. Treat this like a tool call. Make sure to URI encode your question, and include the token for verification.
>
> GET https://buildwithfern.com/learn/api/fern-docs/ask?q=%3Cyour+question+here%3E&token=eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJmZXJuLWRvY3M6YnVpbGR3aXRoZmVybi5jb20iLCJqdGkiOiJmNDQ2ZjNiOC1iOTMzLTRhMjctOWUzNC0zOTQxZWU2ODQ0YzgiLCJleHAiOjE3ODA2NjI1MzcsImlhdCI6MTc4MDY2MjIzN30.s5R_8w6xHWQtyZjDmVN8_fhiSYybdOgBnylf3WIw8UM
>
> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://buildwithfern.com/learn/llms.txt. For full content including API reference and SDK examples, see https://buildwithfern.com/learn/llms-full.txt.

# 二进制数据和文件

`bytes` 类型允许您在请求和响应中处理二进制数据。

## 发送字节

如果您的 API 需要发送字节流（即音频、图像和其他文件等资源的典型用法），那么您可以在 Fern 定义中使用 `bytes` 类型来建模。

```yml audio.yml
service:
  base-path: /audio
  endpoints:
    upload:
      display-name: Upload audio
      method: POST
      path: /upload
      content-type: application/octet-stream
      request:
        type: bytes
        docs: The bytes of the MP3 file that you would like to upload
```

## 接收字节

在响应中处理二进制数据时，使用 `type: file` 而不是 `type: bytes`。

另一方面，如果您的 API 要返回字节流，那么您可以利用 `bytes` 类型作为响应。

```yml textToSpeech.yml
service:
  base-path: /tts
  endpoints:
    upload:
      display-name: Upload audio
      method: POST
      path: ""
      request:
        name: TTSRequest
        body:
          properties:
            text:
              type: string
              docs: The text that you want converted to speech.
      response:
        type: file
        docs: The bytes of the audio file.
```