If you want to send image through post using JSON in flutter? As image picker plugin provides the filePath of the image, you can use File class from dart:io to load the image and BASE64 from dart:convert to convert it as BASE64 string.
Here is how you can do it:
1 2 3 4 5 6 | import 'dart:io'; import 'dart:convert'; File imageFile = new File(imageFilePath); List<int> imageBytes = imageFile.readAsBytesSync(); String base64Image = BASE64.encode(imageBytes); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.