uploadAvatar method

  1. @override
Future<Result<String>> uploadAvatar(
  1. String photoFilePath
)
override

Implementation

@override
Future<Result<String>> uploadAvatar(String photoFilePath) async {
  String uri = '$_appHost/api/v2/upload?folder=avatar';
  var formData = FormData.fromMap({
    'file': await MultipartFile.fromFile(photoFilePath),
  });
  var response = await Dio().post(uri, data: formData);
  if (response.statusCode == 200 || response.statusCode == 201) {
    if (response.data['code'] != 200) {
      return Result.failure(StatusCode.internalServerError,
          '${response.data['message']} (${response.data['code']})');
    }

    return Result.success(response.data['data']?['url']);
  }

  return Result.failure(StatusCode.internalServerError,
      '${response.data['message']} (${response.data['code']})');
}