我有下面的代码来发送一个录制的wav文件到wit.ai API。
Map<String, String> headers = {
'Content-Type': 'audio/wav',
'Authorization': "Bearer $witPublicAPIKey"
};
http.MultipartRequest request =
http.MultipartRequest('POST', Uri.parse(BASE_URL + url));
request.headers.clear();
request.headers.addAll(headers);
request.headers.update('content-type', (value) => 'audio/wav');
request.headers.update('Content-Type', (value) => 'audio/wav');
request.headers.update('Content-Type', (value) => 'audio/wav');
request.files.add(await http.MultipartFile.fromPath('audio', audioUri,
filename: '${audioUri.split('/').last}.wav',
contentType: MediaType('audio', 'wav')));
print("request header is ${request.headers}");
print("request is ${request}");
http.Response res = await http.Response.fromStream(await request.send());
print("Response: ${res.body}");
responseJson = _response(res);
我得到这个错误"error": "Unsupported content-type: 'multipart/form-data;boundary=dart-http-boundary-bpY_n6t9LVcEAVFf7qGYHXDU.H_s1alCjaGGk++6ZOcJ5M4iRFT'"
作为响应。从docs看,HTTP覆盖了我的content-type: audio/wav
头并将其替换为multipart/form-data
。我想通过我的Flutter应用程序上传wav。你知道我该怎么做吗谢谢。
1条答案
按热度按时间ehxuflar1#
这应该可以工作: