我正在尝试在下面上传文本和 pdf 文件代码,但我收到内容大小错误。我正在遵循
文档中的代码,但我不确定我是否以正确的方式进行操作。提前致谢
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;
}
}