'Unhandled Exception: FileSystemException: Cannot retrieve length of file, path = '' (OS Error: No such file or directory, errno = 2)
I want to upload audio file using api in flutter. But getting the given error. Anyone please help or suggestion? My api calling code is:
Future<void> sendAudioMsg(
{required String roomId, required String filePath}) async {
String token = storage.getUserToken();
final headers = {
'Content-Type': 'multipart/form-data',
'Accept': 'application/json',
'Authorization': 'Bearer $token'
};
var request = http.MultipartRequest("POST", Uri.parse(url));
request.fields['room_id'] = roomId;
request.headers.addAll(headers);
var multipartfile = await http.MultipartFile.fromPath(
'file', "assets/audio.acc",
contentType: MediaType('audio', 'acc'));
request.files.add(multipartfile);
var response = await request.send();
var responseData = await response.stream.toBytes();
var responseString = String.fromCharCodes(responseData);
Map<String, dynamic> json = jsonDecode(responseString);
}
Solution 1:[1]
I find out the issue basically my url was not correct.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Muhammad Umair Saqib |
