juhaku / utoipa

Simple, Fast, Code first and Compile time generated OpenAPI documentation for Rust
Apache License 2.0
2.25k stars 175 forks source link

Make implementation for actix MultipartForm #740

Open Geriano opened 1 year ago

Geriano commented 1 year ago
#[utoipa::path(
  tag = "Master Storage",
  context_path = "/api/v1/storage",
)]
#[post("/")]
pub async fn store(
  pool: Data<DbPool>,
  form: MultipartForm<Upload>,
  socket: Data<WebsocketServer>,
) -> Result<impl Responder, Error> {
  /* some code */
}
i007c commented 6 months ago

👍🏻

izolyomi commented 3 months ago

I haven't seen any updates related to this issue yet. I guess it's not planned to be implemented, is it?

As far as I see, multipart forms with file uploads are supported by OpenApi. Is there any other "manual" way to define a proper schema for similar endpoints with Utoipa?

i007c commented 3 months ago

this works fine:

use actix_multipart::form::MultipartForm;
use actix_multipart::form::{tempfile::TempFile, MultipartForm};
use utoipa::ToSchema;

#[derive(Debug, MultipartForm, ToSchema)]
pub struct UpdatePhoto {
    #[schema(value_type = String, format = Binary)]
    #[multipart(limit = "8 MiB")]
    pub photo: TempFile,
}

#[utoipa::path(
    put,
    request_body(content = UpdatePhoto, content_type = "multipart/form-data"),
    responses((status = 200))
)]
#[put("/upload/")]
async fn upload(form: MultipartForm<UpdatePhoto>) -> HttpResponse {}
izolyomi commented 3 months ago

Thank you, works like charm. 👍