step 7 : convert .aac into .mp3
This commit is contained in:
@@ -7,6 +7,56 @@ abstract class BaseRepository {
|
||||
final Dio dio;
|
||||
BaseRepository({required this.dio});
|
||||
|
||||
// POST audio
|
||||
Future<Map<String, dynamic>> postAudio({
|
||||
required String filePath,
|
||||
required String service,
|
||||
String? token,
|
||||
}) async {
|
||||
try {
|
||||
FormData formData = FormData.fromMap({
|
||||
"audio":
|
||||
await MultipartFile.fromFile(filePath, filename: "rekaman.mp3"),
|
||||
});
|
||||
|
||||
final response = await dio.post(
|
||||
// Constant.baseUrl + service,
|
||||
service,
|
||||
data: formData,
|
||||
options: Options(
|
||||
headers: token != null
|
||||
? {
|
||||
HttpHeaders.contentTypeHeader: "multipart/form-data",
|
||||
HttpHeaders.authorizationHeader: "Bearer $token",
|
||||
}
|
||||
: {
|
||||
HttpHeaders.authorizationHeader: "Bearer $token"
|
||||
},
|
||||
contentType: "application/json",
|
||||
),
|
||||
);
|
||||
if (response.statusCode != 200) {
|
||||
throw BaseRepositoryException(
|
||||
message: "Invalid Http Response ${response.statusCode}",
|
||||
);
|
||||
}
|
||||
Map<String, dynamic> jsonData = jsonDecode(response.data);
|
||||
if (jsonData["status"] != "OK") {
|
||||
throw BaseRepositoryException(
|
||||
message: jsonData["message"],
|
||||
);
|
||||
} else {
|
||||
return jsonData;
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
throw BaseRepositoryException(message: e.message ?? "");
|
||||
} on SocketException catch (e) {
|
||||
throw BaseRepositoryException(message: e.message);
|
||||
} on BaseRepositoryException catch (e) {
|
||||
throw BaseRepositoryException(message: e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// POST PAKE ContentType JSON
|
||||
Future<Map<String, dynamic>> post({
|
||||
required Map<String, dynamic> param,
|
||||
@@ -103,4 +153,4 @@ class BaseRepositoryException implements Exception {
|
||||
BaseRepositoryException({
|
||||
required this.message,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user