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

Make implementation for actix MultipartForm #740

Open
Geriano opened this issue Aug 17, 2023 · 5 comments
Open

Make implementation for actix MultipartForm #740

Geriano opened this issue Aug 17, 2023 · 5 comments

Comments

@Geriano
Copy link

Geriano commented Aug 17, 2023

#[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
Copy link

i007c commented Mar 11, 2024

👍🏻

@izolyomi
Copy link

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
Copy link

i007c commented Jun 12, 2024

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
Copy link

Thank you, works like charm. 👍

@juhaku
Copy link
Owner

juhaku commented Oct 10, 2024

I am not sure what kind of information should be possible to extract form the actix-web multipart data. However the multipart thing will change a bit in coming utoipa 5.0.0. Here is PR which adds some examples for the file upload #1113.

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

No branches or pull requests

4 participants