I'm trying to upload text and pdf files
code below but I'm receiving the error in the content size. I'm following
the code in the document but I'm not sure if I'm doing it the right
way. Thanks in advance
Future<void> _postCallCreate(String fileNames, String urlSegment) async {
Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
'Authorization': _token,
};
final url = Constants.BASE_URL + urlSegment;
try {
var request = http.MultipartRequest('POST', Uri.parse(url));
request.files.add(http.MultipartFile(
'dto',
File(fileNames).readAsBytes().asStream(),
File(fileNames).lengthSync(),
filename: fileNames.split("/").last));
print(request.files.first);
request.headers.addAll(requestHeaders);
var res = await request.send();
print(res.reasonPhrase);
notifyListeners();
} catch (error) {
print(error);
throw error;
}
}