Header Implementations "Content-Disposition"

# by analogy
# python as an example
output = io.StringIO()
fle = csv.writer(output)
content = output.getvalue()
headers = {"Content-Disposition": "attachment;filename=as.csv"}
return Response(content, headers=headers)

// axum rust as an example
use axum::{
        Response, StatusCode,
use csv::Writer;

pub async fn import_users(State(pool): State<Pool>) -> impl IntoResponse {
let mut conn = pool.get().await.unwrap();
use schema::users::dsl::*;
let data = users
    .load(&mut conn)
let mut wtr = Writer::from_writer(vec![]);
for pat in data {
return Response::builder()
    .header("Location", "/")
    .header("Content-Disposition", "attachment;filename=or.csv")

I've been looking for solutions for a long time, I hope for help.

error[E0277]: the trait bound `Body: From<Writer<Vec<u8>>>` is not satisfied
  --> src\import_export\handlers.rs:51:15
51 |         .body(Body::from(wtr))
   |               ^^^^ the trait `From<Writer<Vec<u8>>>` is not implemented for `Body`
   = help: the following other types implement trait `From<T>`:
             <Body as From<axum::body::Bytes>>
             <Body as From<Cow<'static, str>>>
             <Body as From<Cow<'static, [u8]>>>
             <Body as From<Vec<u8>>>
             <Body as From<std::string::String>>
             <Body as From<&'static str>>
             <Body as From<&'static [u8]>>
             <Body as From<()>>

I'm guessing you're trying to do something like

1 Like

Thank you sincerely

1 Like