Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
1
Indexable
Never
Future<Response> setHelpContentWithMedia(
    Map<String, String> body,
    File media,
    bool isVisitor,
  ) async {
    final Uri uri = Uri.parse(
      isVisitor ? ApiString.setSubjectsHelpVisitor : ApiString.setSubjectsHelp,
    );
    http.MultipartRequest request = new http.MultipartRequest('POST', uri);

    request.fields.addAll(body);

    if (isVisitor) {
      request.headers.addAll(<String, String>{
        'Content-Type': 'multipart/form-data',
      });
    } else {
      request.headers.addAll(<String, String>{
        'Content-Type': 'multipart/form-data',
        'Authorization': await handleRefreshToken(
          'Bearer ' + appUser.state.tokens!.access!.token!,
          false,
        )
      });
    }

    final Future<http.MultipartFile> httpImage = http.MultipartFile.fromPath(
      'filename',
      media.path,
    );

    request.files.add(await httpImage);
    final http.StreamedResponse response = await request.send();
    final http.Response res = await http.Response.fromStream(response);

    return res;
  }