extractFilesData method
Returns a list of fileData elements, one for each file to upload. Each element is a triple containing fileField, full filePath, mimeType
The lists are stored in the similarly named String fields as a JSON list, with each list the same length. For the filenames list, if a filename refers to a file that exists (i.e. it is a full path) then that is the filePath used, otherwise the filename is appended to the Task.baseDirectory and Task.directory to form a full file path
Implementation
Future<List<(String, String, String)>> extractFilesData() async {
final List<String> fileFields = List.from(jsonDecode(fileField));
final List<String> filenames = List.from(jsonDecode(filename));
final List<String> mimeTypes = List.from(jsonDecode(mimeType));
final result = <(String, String, String)>[];
for (int i = 0; i < fileFields.length; i++) {
final file = File(filenames[i]);
if (await file.exists()) {
result.add((fileFields[i], filenames[i], mimeTypes[i]));
} else {
result.add(
(
fileFields[i],
await filePath(withFilename: filenames[i]),
mimeTypes[i],
),
);
}
}
return result;
}