I'm trying to make a web application in flutter and i should send a pdf file to a rest api. I tried a few things but actually i have no idea about what i did and what should i do. My code is below, but probably it does'nt make any sense. So my question is, how can i post this pdf? Here's my http request:
final request = http.MultipartRequest('POST', uri);
request.headers.addAll(headers);
request.fields.addAll(requestModel.toJson());
request.files.add(http.MultipartFile.fromBytes(
"receipt", await requestModel.receipt.readAsBytes(),
contentType: MediaType('document', 'pdf'), filename: "receipt.pdf"));
var response = await request.send();
var responseBody = await response.stream.bytesToString();
log('responseBody is => ${responseBody}');
log('responseStatus => ${response.statusCode}');
And the request models fields are here:
late double amount;
late int paymentId;
late File receipt;
late String upStatus;