Flutter:使用二进制体上传图像

Lit*_*key 4 binary upload dart flutter

我想使用二进制文件上传文件,如截图所示:

截屏

到目前为止,我只有:

      save() async {
         http.put(url,headers:headers, body: );
Run Code Online (Sandbox Code Playgroud)

Xav*_*ier 7

该方法的body参数put接受List<int>将用作字节列表的 a

来自httpAPI 参考:https : //pub.dev/documentation/http/latest/http/put.html

body 设置请求的正文。它可以是字符串、列表或地图。如果是字符串,则使用编码对其进行编码并用作请求的正文。请求的内容类型将默认为“text/plain”。

如果 body 是一个 List,它被用作请求正文的字节列表。

如果 body 是 Map,则使用 encoding 将其编码为表单字段。请求的内容类型将设置为“application/x-www-form-urlencoded”;这不能被覆盖。

发送文件的示例:

main() async {
  await put(url, body: File('the_file').readAsBytesSync());
}
Run Code Online (Sandbox Code Playgroud)