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();
|
2024-01-02 13:53:21 +01:00
|
|
|
Future<String> checkLang(Uint8List imageBytes, String imageName) async {
|
|
|
|
var client = http.Client();
|
|
|
|
|
2023-11-21 19:48:58 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|