I am trying to consume this API for dart using Flutter: https://pixcut.wondershare.com/api.html. My images are saved in the database as strings, and I am using methods to convert to string, Uint8list or Image as you can see below. I am trying to use http.MultipartRequest to get the image without background, but I get this error:
[log] {"Code":10001,"Msg":"fail msg : http: no such file","Data":null}
void removeBackground(String image) async {
var request = http.MultipartRequest(
"POST", Uri.parse('https://pixcut.wondershare.com/openapi/api/v1/matting/removebg'));
request.headers.addAll(
{
r'Content-Type': 'multipart/form-data',
r'appkey': '061c4600615d101a56330357cafce7d9',
},
);
request.files
.add(http.MultipartFile.fromBytes('content', CleverCloset.dataFromBase64String(image) // use the real name if available, or omit
));
await request.send().then((response) {
http.Response.fromStream(response).then((onValue) {
try {
log(onValue.body);
//stackChildren.add(MoveableStackItem(CleverCloset.imageFromBase64String(onValue.body).image));
log("bb");
setState(() {
});
// get your response here...
} catch (e) {
log(e.toString());
log("ddd");
// handle exeption
}
});
});
}
static Uint8List dataFromBase64String(String base64String) {
return base64Decode(base64String);
}
static String base64String(Uint8List data) {
return base64Encode(data);
}