add imgPath

This commit is contained in:
Valentin CZERYBA 2024-09-12 23:54:59 +02:00
parent 4f12fdf8b3
commit 6fd00ddd98

View File

@ -5,6 +5,7 @@ import 'package:intl/intl.dart';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import '../classes/alert.dart';
import '../classes/eventAdded.dart';
@ -116,6 +117,25 @@ class _UpdateeventImageState extends State<UpdateeventImage>
List<String> send = ["toto"];
if (accessToken.isNotEmpty) {
try {
final params = {
'expiration': '600',
'key': '87a91f7e54516808dda2c4feffbd5287',
};
final urlPost = Uri.parse('https://api.imgbb.com/1/upload')
.replace(queryParameters: params);
File image = File(widget.imagePath);
Uint8List _bytes = await image.readAsBytes();
String _base64String = base64.encode(_bytes);
final req = http.MultipartRequest('POST', url)
..fields['image'] = _base64String;
final stream = await req.send();
final res = await http.Response.fromStream(stream);
final status = res.statusCode;
if (status == 200) {
//String credentials = "${pseudo}:${password}";
//Codec<String, String> stringToBase64 = utf8.fuse(base64);
//String encoded = stringToBase64.encode(credentials);
@ -184,6 +204,9 @@ class _UpdateeventImageState extends State<UpdateeventImage>
}
showErrorDialog(context, text);
}
} else {
print("imgbb error : ${status}");
}
} catch (e) {
showErrorDialog(context, "${e}");
}