Post Multiple Images to server

994 views
Skip to first unread message

Kamran Ali

unread,
Jun 5, 2019, 6:02:05 AM6/5/19
to Flutter Dev
I used dio library to post file to a server and it is working fine, now i want to post multiple images to server that user selects from gallery, following is the code from documentation of dio library for uploading multiple files
FormData formData = new FormData.from({
"name": "wendux",
"age": 25,
"file1":
new UploadFileInfo(new File("./upload.txt"), "upload1.txt"),
// upload with bytes (List<int>)
"file2":
new UploadFileInfo.fromBytes(
utf8.encode("hello world"), "word.txt"),
// Pass multiple files within an Array
"files": [
new UploadFileInfo(new File("./example/upload.txt"), "upload.txt"),
new UploadFileInfo(new File("./example/upload.txt"), "upload.txt")
]
});
my question is that how can i implement this in my code for images?? because i don't know that how many images are selected by user.

Kamran Ali

unread,
Jun 5, 2019, 7:07:56 AM6/5/19
to Flutter Dev
anyone??

Kamran Ali

unread,
Jun 5, 2019, 10:47:35 AM6/5/19
to Flutter Dev
Following code solved my issue:

List uploadList = [];

for (var imageFiles in _list) {
uploadList.add(UploadFileInfo(File(imageFiles), "test.jpg"));
};

and in FormData i just pass this uploadList:

"image_list": uploadList,
  

Vastravibe Traditional Fashion

unread,
Aug 1, 2019, 7:02:51 AM8/1/19
to Flutter Development (flutter-dev)
for multiple images which image are you use?
Reply all
Reply to author
Forward
0 new messages