bg method
Future<Uint8List?>
bg(
- File file, {
- required String privateKey,
- required OnUploadProgressCallback onUploadProgressCallback,
Implementation
Future<Uint8List?> bg(
File file, {
required String privateKey,
required OnUploadProgressCallback onUploadProgressCallback,
}) async {
String apiUrl = "https://api.remove.bg/v1.0/removebg";
// String username = 'V4jfAbeYFHg58sEBazqAXzCM';
// String password = '';
// String basicAuth = 'Basic ${base64Encode(utf8.encode('$username:$password'))}';
String fileName = file.path.split('/').last;
var formData = FormData.fromMap({
'image_file': await MultipartFile.fromFile(file.path, filename: fileName),
'size': "auto",
});
try {
Response response = await dio.post(
apiUrl,
data: formData,
options: Options(
headers: {
'X-API-Key': privateKey,
// 'Accept': 'image/png',
},
responseType: ResponseType.bytes,
),
onSendProgress: (count, total) {
double progress = count / total;
onUploadProgressCallback(progress);
},
);
final getApi = response.data;
/// Received `Bytes` Response
return getApi;
} on DioError catch (e) {
debugPrint(e.message);
}
return null;
}