Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint API:‌ Support octet-stream Media-type For Multipart Form Fields #2746

Closed
khajavi opened this issue Mar 26, 2024 · 4 comments · Fixed by #2926
Closed

Endpoint API:‌ Support octet-stream Media-type For Multipart Form Fields #2746

khajavi opened this issue Mar 26, 2024 · 4 comments · Fixed by #2926
Labels

Comments

@khajavi
Copy link
Member

khajavi commented Mar 26, 2024

I expect to have binary form fields to upload files in the Endpoint API using the octet-stream media type, but currently, the Endpoint API doesn't support such media type and throws an exception.

import zio._
import zio.http._
import zio.http.endpoint.Endpoint

object MultipartFormDataEndpointExample extends ZIOAppDefault {
  def run =
    Server
      .serve(
        Endpoint(RoutePattern.POST / "books")
          .in[String]("title")
          .in[String]("author")
          .in[Chunk[Byte]](MediaType.application.`octet-stream`, "file")
          .out[Unit]
          .implement(handler { (title: String, author: String, file: Chunk[Byte]) =>
            ZIO.debug("Handler called!")
          })
          .toHttpApp @@ Middleware.debug,
      )
      .provide(Server.default, Scope.default)
}

The console output when I run the above example:

import zio._
import zio.http._
import zio.http.endpoint.Endpoint

object MultipartFormDataEndpointExample extends ZIOAppDefault {
  def run =
    Server
      .serve(
        Endpoint(RoutePattern.POST / "books")
          .in[String]("title")
          .in[String]("author")
          .in[Chunk[Byte]](MediaType.application.`octet-stream`, "file")
          .out[Unit]
          .implement(handler { (title: String, author: String, file: Chunk[Byte]) =>
            ZIO.debug("Handler called!")
          })
          .toHttpApp @@ Middleware.debug,
      )
      .provide(Server.default, Scope.default)
}
@khajavi khajavi added the enhancement New feature or request label Mar 26, 2024
@jdegoes
Copy link
Member

jdegoes commented Jun 5, 2024

/bounty $150

Copy link

algora-pbc bot commented Jun 5, 2024

💎 $150 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #2746 with your implementation plan
  2. Submit work: Create a pull request including /claim #2746 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bountyShare on socials

Attempt Started (GMT+0) Solution
🟢 @987Nabil #2926

Copy link

algora-pbc bot commented Jun 21, 2024

💡 @987Nabil submitted a pull request that claims the bounty. You can visit your bounty board to reward.

Copy link

algora-pbc bot commented Jun 23, 2024

🎉🎈 @987Nabil has been awarded $150! 🎈🎊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants