I have this code
#[api_operation(
tag = "image",
summary = "uploads an image",
description = r###"upload an image to an account"###,
error_code = 405
)]
pub async fn upload_image(mut payload: Multipart) -> impl Responder {
let upload_dir = std::env::var("UPLOAD_DIR").unwrap_or_else(|_| "./uploads".to_string());
let upload_status = files::save_file(payload, format!("{upload_dir}/test.png").to_string()).await;
which to me looks like an async
method.
but for some reason I am getting compile errors
error[E0728]: `await` is only allowed inside `async` functions and blocks
--> src/image.rs:18:97
|
9 | / #[api_operation(
10 | | tag = "image",
11 | | summary = "uploads an image",
12 | | description = r###"upload an image to an account"###,
13 | | error_code = 405
14 | | )]
| |__- this is not `async`
...
18 | let upload_status = files::save_file(payload, format!("{upload_dir}/test.png").to_string()).await;
| ^^^^^ only allowed inside `async` functions and blocks
is it saying that the macro is causing it not to be async, or why can’t I use await?
and is there any way around it?
8
This was a bug in the apistos::api_operation
macro, it has since been resolved and your code does work with versions that include the corresponding code changes