I have the code below to send a recorded wav file to the 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);
I get this error "error": "Unsupported content-type: 'multipart/form-data;boundary=dart-http-boundary-bpY_n6t9LVcEAVFf7qGYHXDU.H_s1alCjaGGk++6ZOcJ5M4iRFT'"
as the response. It seems from the docs that HTTP overrides my content-type: audio/wav
header and replaces it with multipart/form-data
. I would like to upload the wav through my flutter app. Any idea how I can achieve that? Thanks.