I have a List of images as bytes and I would like to send it as a post request in flutter web.
Firstly how do I send the data in file format just like image picker for android/iOS in flutter web
Secondly if I had to send the attachments in the below code what changes would I need to make in multipart in flutter web
If anyone can please help me resolve this.
Let me know if you require any further information from my end
dataInsert.dart
File _file = File("zz");
Uint8List webImage = Uint8List(10);
else if (kIsWeb) {
final imagefile =
await picker.pickImage(source: ImageSource.gallery, maxWidth: 600);
if (imagefile != null) {
var f = await imagefile.readAsBytes();
setState(() {
_file = File("a");
webImage = f;
_storedImageWeb.add(webImage);
});
}
}
Below is the value of webImage on running the above code :
[255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, 226, 2, 40, 73, 67, 67, 95, 80, 82, 79, 70, 73, 76, 69, 0, 1, 1, 0, 0, 2, 24, 0, 0, 0, 0, 4, 48, 0, 0, 109, 110, 116, 114, 82, 71, 66, 32, 88, 89, 90, 32, 0, 0, 0, 0, 0, 0, 0, 0]
Multipart.dart
Future<void> addUser(
ProjectDetail stnotification, List<Uint8List> imagecheckb) async {
Map<String, String> headers = {
"Content-Type": "charset=utf-8",
"Content-type": "application/json"
};
var uri = Uri.parse('http://localhost:4000/check/upload');
try {
var request = http.MultipartRequest('POST', uri);
request.headers.addAll(headers);
for (int i = 0; i <= imagecheckb.length - 1; i++) {
http.MultipartFile multipartFile = await http.MultipartFile.fromBytes(
'attachments', imagecheckb[i].cast());
request.files.add(multipartFile);
}