-
I have this route handler that take a Vec from Sqlx and returns web::Bytes, but my client cannot read it for some reason. Am I doing the route correctly? pub async fn get_message_image<T: QueryMessageImageFn>(app_data: web::Data<AppState<T>>, path: Path<MessageQuery>) -> actix_web::Result<actix_web::HttpResponse> {
let message_result = app_data.db_repo.query_message_image(path.id).await;
match message_result {
Ok(option_image) => {
match option_image {
Some(msg_image) => {
let file_bytes: Bytes = Bytes::from(msg_image.image);
// Return the file as a response
Ok(HttpResponse::Ok()
.content_type("image/jpeg") // Set the appropriate content type for your file
.body(file_bytes))
},
None => Ok(HttpResponse::NotFound().body("File not found"))
}
},
Err(e) => Ok(HttpResponse::NotFound().body("File not found"))
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
There's nothing obviously wrong with this. How are you testing it? |
Beta Was this translation helpful? Give feedback.
-
Hey Rob. I'm calling this from a react native app, which uses js for its language |
Beta Was this translation helpful? Give feedback.
-
Thanks Rob. Yes getting it with curl retrieves a file with the same garbled image. Is it possible then that my upload is breaking the file format? I receive the file as a multipart object called MessageCreateMultipart, which does an impl on FromRequest. Here's my code.
|
Beta Was this translation helpful? Give feedback.
-
Love it. That did it thank you. Also thank you and team for the work you're doing on actix web. |
Beta Was this translation helpful? Give feedback.
This is incorrect.
bytes
here is actually a chunk, not a complete file, so you need to append each chunk uploaded to a buffer before it is a complete image