无法从文件检索文件长度

时间:2019-10-15 11:20:57

标签: flutter dart

我正在尝试将带有某些图像文件的请求发布到服务器,但是当我尝试检索文件长度时出现此错误:

  

(FileSystemException)“无法检索文件的长度”

这是我的代码:

static Future<String> registerPersonImage(List<File> images, int id) async {
  var url = _session._getUrl('/persons/$id/add-rec-assets/');
  var uri = Uri.parse(url);
  print(url);
  var csrf = App.getValue('CSRF', '');
  var request = http.MultipartRequest("POST", uri);

  var headers = {
    'X-CSRFToken': csrf,
    'cookie': _session.headers['cookie']
  };

  for (final image in images) {
    var stream = new http.ByteStream(
        DelegatingStream.typed(image.openRead()));
    var length = await image.length();

    var multipartFile = http.MultipartFile('file', stream, length);
    request.files.add(multipartFile);
  }

  var response = await request.send();

  print(response.statusCode);
  response.stream.transform(utf8.decoder).listen((value) {
  print(value);
  });
  return 'abc';
}

0 个答案:

没有答案