request http imgbb

This commit is contained in:
Valentin CZERYBA 2024-09-17 23:09:35 +02:00
parent 6fd00ddd98
commit 54247f8c56

View File

@ -121,21 +121,25 @@ class _UpdateeventImageState extends State<UpdateeventImage>
'expiration': '600', 'expiration': '600',
'key': '87a91f7e54516808dda2c4feffbd5287', 'key': '87a91f7e54516808dda2c4feffbd5287',
}; };
print("Post Img");
final urlPost = Uri.parse('https://api.imgbb.com/1/upload') final urlPost = Uri.parse('https://api.imgbb.com/1/upload')
.replace(queryParameters: params); .replace(queryParameters: params);
File image = File(widget.imagePath); File image = File(widget.imagePath);
Uint8List _bytes = await image.readAsBytes(); Uint8List _bytes = await image.readAsBytes();
String _base64String = base64.encode(_bytes); String _base64String = base64.encode(_bytes);
final req = http.MultipartRequest('POST', url) final req = http.MultipartRequest('POST', urlPost)
..fields['image'] = _base64String; ..fields['image'] = _base64String;
final stream = await req.send(); final stream = await req.send();
final res = await http.Response.fromStream(stream); final res = await http.Response.fromStream(stream);
final status = res.statusCode; final status = res.statusCode;
print("code status imgbb ${status}");
if (status == 200) { if (status == 200) {
var body = json.decode(utf8.decode(res.bodyBytes));
String imgUrl = body["data"]["url"];
//String credentials = "${pseudo}:${password}"; //String credentials = "${pseudo}:${password}";
//Codec<String, String> stringToBase64 = utf8.fuse(base64); //Codec<String, String> stringToBase64 = utf8.fuse(base64);
//String encoded = stringToBase64.encode(credentials); //String encoded = stringToBase64.encode(credentials);
@ -157,7 +161,8 @@ class _UpdateeventImageState extends State<UpdateeventImage>
'organizers': send, 'organizers': send,
'latitude': '0.0', 'latitude': '0.0',
'longitude': '0.0', 'longitude': '0.0',
'description': description 'description': description,
"imgUrl": imgUrl
})); }));
print(responsePut.statusCode); print(responsePut.statusCode);
if ((responsePut.statusCode == 200) || if ((responsePut.statusCode == 200) ||