length property

int length

The total length of the request body, in bytes. This is calculated from fields and files and cannot be set manually.

Implementation

int get length {
  var length = 0;
  fields.forEach((entry) {
    length += '--'.length +
        _BOUNDARY_LENGTH +
        '\r\n'.length +
        utf8.encode(_headerForField(entry.key, entry.value)).length +
        utf8.encode(entry.value).length +
        '\r\n'.length;
  });

  for (var file in filesNew) {
    int l = 0;
    if (file.value is http.MultipartFile) {
      http.MultipartFile f = file.value as http.MultipartFile;
      l = int.parse(f.length.toString());
    } else if (file.value is MultipartFile) {
      MultipartFile f = file.value as MultipartFile;
      l = int.parse(f.length.toString());
    }

    print("文件大小:" + l.toString());
    length += '--'.length +
        _BOUNDARY_LENGTH +
        '\r\n'.length +
        utf8.encode(_headerForFile(file)).length +
        l +
        '\r\n'.length;
  }

  return length + '--'.length + _BOUNDARY_LENGTH + '--\r\n'.length;
}