upload method
Implementation
Future<List<Attachment>> upload(
int id, int version, Iterable<File> files) async {
final data = FormData();
for (var file in files) {
var fileName = file.path.split('/').last;
fileName = DateFormat('yyMMddhhmmss').format(DateTime.now()) +
fileName.substring(fileName.lastIndexOf('.'));
data.files.add(MapEntry(
fileName,
await MultipartFile.fromFile(
file.path,
contentType: MediaType.parse(lookupMimeType(file.path) ?? ""),
)));
}
try {
final response = await dio.post('/attachments/$id',
queryParameters: {'version': version}, data: data);
return List.from(response.data.map((a) => Attachment.fromJson(a)));
} on DioException catch (e) {
_handleError(e);
rethrow;
}
}