如何在Flutter中使用JSON通过帖子发送图片?
问题内容:
我正在构建一个flutter应用程序,该应用程序利用图像选择器捕获或从图库中选择图像,但是我很难将图像从客户端发布到服务器。
从我收集的数据中,我可以通过将图像文件转换为字节,然后将其作为BASE64发送来通过JSON发送本地图像。
import 'dart:convert';
import 'package:crypto/crypto.dart';
Future<Map> _avatarSubmit() async {
String url = api + '/api/account';
http.Response response = await http.post(Uri.encodeFull(url), headers: {
"Accept": "application/json",
"Cookie": "MYCOOKIE=" + sessionCookie2 + "; MYTOKENS=" + sessionCookie3,
"Content-type": "multipart/form-data",
}, body: {
"image": "",
});
Map content = JSON.decode(response.body);
return content;
}
我的问题是如何将设备中的图像文件转换为字节,以便随后可以使用加密插件将其转换为BASE64?
先感谢您。
问题答案: