Hey
I have a form with a lot of data like name, address,... which I can successfully POST to Actix-web. But now I also want to mix a file into that form-data.
JQuery (Works fine):
let file = $("#image")[0].files[0];
let data = new FormData();
data.append("name", $("#name").val());
data.append("description", $("#description").val());;
data.append("tel", $("#tel").val());
data.append("email", $("#email").val());
data.append("file", file);
$.ajax({
type: 'POST',
data: data,
cache: false,
contentType: false,
processData: false,
url: url,
success: function(response) {
console.log(response)
}
});
This is my struct and here is the problem:
#[derive(Deserialize)]
struct AddDistributorForm {
name: String,
description: String,
tel: String,
email: String,
file: Multipart,
}
gives the following errors:
the trait bound `Multipart: _::_serde::Deserialize<'_>` is not satisfied required by `next_element`
the trait bound `Multipart: _::_serde::Deserialize<'_>` is not satisfied required by `next_value`
have already implemented
a file upload system in Rust
once, but then I was using the Multipart
variable as a separated parameter and not mixed with other attributes in form-data.
How would I fix this?