Cartoon yourself

FREEMIUM
By AILabTools | Updated 20 дней назад | Visual Recognition
Popularity

9 / 10

Latency

2,642ms

Service Level

98%

Health Check

100%

Back to All Discussions

i can't use api with flutter

Rapid account: Ma 7 M 0 O 0 Odadel
ma7m0o0odadel
4 месяца назад

i have two function to send and get api , and i used two butoon to do this but when i press on send ,i found issues and found message error , can any person help me ?
Future<void> sendImage() async {
try {
var uri = Uri.parse(
https://cartoon-yourself.p.rapidapi.com/facebody/api/portrait-animation/portrait-animation’);

  var request = http.MultipartRequest('POST', uri);
  request.headers.addAll({
    'X-RapidAPI-Key': '94f3c575c8mshbe398b0925692f0p1a25c4jsn176f63fa51f6',
    'X-RapidAPI-Host': 'cartoon-yourself.p.rapidapi.com',
  });

  var imageFile = File(image_picker!.path);
  request.files.add(await http.MultipartFile.fromPath(
    'image',
    imageFile.path,
    contentType: MediaType('image', 'jpg'),
  ));

  var response = await request.send();
  if (response.statusCode == 200) {
    var responseData = await response.stream.bytesToString();
    print(responseData);
  } else {
    print('حدث خطأ: ${response.statusCode}');
  }
} catch (error) {
  print('حدث خطأ أثناء إرسال الصورة: $error');
}

}

Future<void> fetchImage() async {
final uri = Uri.parse(
https://cartoon-yourself.p.rapidapi.com/facebody/api/portrait-animation/portrait-animation’);

String imageFilePath = image_picker!.path;
var imageBytes = await File(imageFilePath).readAsBytes();

var request = http.MultipartRequest('POST', uri);

request.headers.addAll({
  'X-RapidAPI-Key': '94f3c575c8mshbe398b0925692f0p1a25c4jsn176f63fa51f6',
  'X-RapidAPI-Host': 'cartoon-yourself.p.rapidapi.com',
  'Content-Type': 'multipart/form-data',
});

request.files.add(http.MultipartFile.fromBytes(
  'image',
  imageBytes,
  filename: 'image.jpg',
  contentType: MediaType('image', 'jpg'),
));

try {
  var response = await request.send();
  if (response.statusCode == 200) {
    var responseData = await response.stream.toBytes();

    var responseString = utf8.decode(responseData);

    var jsonResponse = json.decode(responseString);

    var convertedImageBytes = base64.decode(jsonResponse['imageData']);
    var convertedImage = Image.memory(convertedImageBytes);

  } else {
    print('فشل الطلب: ${response.reasonPhrase}');
  }
} catch (error) {
  print('حدث خطأ أثناء إرسال الصورة: $error');
}

}

Join in the discussion - add comment below:

Login / Signup to post new comments