scrapImages method

Future<List<String>> scrapImages (List<File> images)

Uploads a list of images to storage server used by Kakao API.

Returned list of image urls can be passed to StoryApi.postPhotos().

Implementation

Future<List<String>> scrapImages(List<File> images) async {
  return ApiFactory.handleApiError(() async {
    Map<String, UploadFileInfo> data = images.asMap().map((index, image) =>
        MapEntry("file_${index + 1}",
            UploadFileInfo(image, image.path.split("/").last)));
    final response = await _dio.post("/v1/api/story/upload/multi",
        data: FormData.from(data));
    var urls = response.data;
    if (urls is List) return urls.map((url) => url as String).toList();
    throw KakaoClientException("Resposne should be an array.");
  });
}