[英]How to upload an image in memory, as a binary image on the body in Flutter web?
所以在这篇文章的那一刻,我尝试使用DIO库,但目前他们提供的所有不同方法都不适合我。
在有人为 flutter 本身(非移动设备)提出的类似问题之后,这里提供的答案之一是:@Mehul Prajapati: https://stackoverflow.com/a/64604174/8377232 。
我做了以下事情:
代替 Dio 库,使用http库,如下所示:
Future<void> _uploadImage(Uint8List binaryImage) async {
Response response = await http.post(
Uri.parse('<your url here> '),
headers: {
'Content-Type': "text/plain",
'Accept': "*/*",
'Content-Length': binaryImage.toString(),
'Connection': 'keep-alive',
},
body: binaryImage,
);
}
为了获得 binaryImage 本身(这是一个 int8 数字数组),我做了以下事情: 这是我发送给上述方法的值,您可能还需要根据服务器 API 的需要修改内容类型:修改为“image/jpeg”之类的内容或任何需要的内容。
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.