ANDREAS_LATANOWSKY_CPD_1910877/lib/http_utils.dart

33 lines
1.0 KiB
Dart
Raw Normal View History

2023-11-21 19:48:58 +01:00
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart';
class HttpUtils {
var client = http.Client();
Future<String> performHttpRequest(
Uint8List imageBytes, String imageName) async {
var postUri = Uri.parse("http://130.61.88.150/upload");
http.MultipartRequest request = http.MultipartRequest("POST", postUri);
http.MultipartFile multipartFile = http.MultipartFile.fromBytes(
'file',
imageBytes,
filename: 'lorem.png',
contentType: MediaType('image', 'png'),
);
request.files.add(multipartFile);
http.StreamedResponse response = await client.send(request);
http.Response finalResponse = await http.Response.fromStream(response);
var lang = "";
if (finalResponse.statusCode == 200) {
Map<String, dynamic> jsonData = jsonDecode(finalResponse.body);
lang = jsonData['language'];
} else {
throw ('Error: ${finalResponse.statusCode}');
}
return lang;
}
}