You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a feature, need to send multi file with params, it is wrong to use FormData.fromMap.
server will receive null on formFile
var files = [];
for (int i = 0; i < imgList.length; i++) {
final element = imgList[i];
final file = await MultipartFile.fromFile(element.path);
var fileData = {
"spec_id": element.spec_id,
"name": element.name,
"formfile": file,
};
files.add(fileData);
}
var sendData = {
"files": files,
};
var formData = FormData.fromMap(sendData);
right way
var formData = FormData();
for (int i = 0; i < imgList.length; i++) {
final element = imgList[i];
final file = await MultipartFile.fromFile(element.path);
formData.files.add(MapEntry("files[$i].formfile", file));
formData.fields.add(MapEntry("files[$i].spec_id", element.spec_id));
formData.fields.add(MapEntry("files[$i].name", element.name));
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a feature, need to send multi file with params, it is wrong to use FormData.fromMap.
server will receive null on formFile
right way
server code
Beta Was this translation helpful? Give feedback.
All reactions