uploadImages method

Future uploadImages(
  1. List<String> imagePaths,
  2. String businessId
)

Implementation

Future<dynamic> uploadImages(
    List<String> imagePaths, String businessId) async {
  Uri url = Uri.parse('$baseUrl/${ApiUrls.sendImage(businessId)}');
  http.MultipartRequest request = http.MultipartRequest(ApiMethods.post, url);

  for (int i = 0; i < imagePaths.length; i++) {
    http.MultipartFile multipartFile =
        await http.MultipartFile.fromPath('images', imagePaths[i]);

    request.files.add(multipartFile);
  }

  dynamic responseList = [];

  try {
    http.StreamedResponse streamedResponse = await request.send();
    final response = await http.Response.fromStream(streamedResponse);
    if (response.statusCode == 200) {
      final Map<String, dynamic> responseData = json.decode(response.body);
      responseList = List<String>.from(responseData['data']);
      return responseList;
    } else {
      return [];
    }
  } catch (error) {
    return [];
  }
}