Flutter: upload image using binary body
The body
parameter of the put
method accepts a List<int>
that will be used as a list of bytes
From the http
API reference: https://pub.dev/documentation/http/latest/http/put.html
body sets the body of the request. It can be a String, a List or a Map. If it's a String, it's encoded using encoding and used as the body of the request. The content-type of the request will default to "text/plain".
If body is a List, it's used as a list of bytes for the body of the request.
If body is a Map, it's encoded as form fields using encoding. The content-type of the request will be set to "application/x-www-form-urlencoded"; this cannot be overridden.
Examples to send a file:
main() async {
await put(url, body: File('the_file').readAsBytesSync());
}
Comments
-
Little Monkey over 1 year
I want to upload a file using binary body like in the screenshot:
So far I just have:
save() async { http.put(url,headers:headers, body: );
-
Elia Weiss over 4 yearsWhat is DelegatingStream?
-
Deepak gupta almost 3 yearsWorked for me. I was uploading the file on AWS3 bucket and not able to send file over the server but this solution helped me lot. Thanks @Xavier.
-
M.SH almost 2 yearsWorked well :+1