uploadScreenshots method
Implementation
Future<Response> uploadScreenshots(String reportId, List<File> screenshots,
String reportingTokenCall) async {
try {
if (screenshots.isEmpty) {
return Response(requestOptions: RequestOptions(path: ''), data: '');
}
List<MultipartFile> multipartFiles = [];
for (File screenshot in screenshots) {
String fileName = path.basename(screenshot.path);
MultipartFile multipartFile = await MultipartFile.fromFile(
screenshot.path,
filename: fileName,
contentType: MediaType.parse(
'image/png'), // Assuming screenshots are png images
);
multipartFiles.add(multipartFile);
}
FormData formData = FormData.fromMap({
'bitmaps': multipartFiles,
});
final response = await _dio.post(
QuashConstants.baseUrl +
QuashConstants.updateBugEndPoint +
reportId +
QuashConstants.bitmaps,
data: formData,
options: Options(
contentType: 'multipart/form-data',
headers: {
'Authorization': 'Bearer $reportingTokenCall',
},
),
);
ScreenCapture().stopCapturing();
ScreenCapture().clearBitmaps();
return response;
} on Exception catch (e) {
if (kDebugMode) {
print('Exception occurred while uploading screenshots: $e');
}
return Response(requestOptions: RequestOptions(path: ''), data: '');
}
}