Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart Html-将Blob转换为文件_Dart_Dart Html - Fatal编程技术网

Dart Html-将Blob转换为文件

Dart Html-将Blob转换为文件,dart,dart-html,Dart,Dart Html,我正试图为一些dart:html代码编写一个测试 我有一个带有文件参数的方法(html文件,而不是io文件) 我可以用文件所需的数据(减去文件名、日期等)创建一个Blob,但似乎无法在dart:html中创建文件对象,因为它在html_dartium.dart中保留供内部使用 factory File._() { throw new UnsupportedError("Not supported"); } 有没有其他方法来创建HTML文件对象 我见过前面提到的文件阅读器,但是这些阅读器的结果要

我正试图为一些dart:html代码编写一个测试

我有一个带有文件参数的方法(html文件,而不是io文件)

我可以用文件所需的数据(减去文件名、日期等)创建一个Blob,但似乎无法在dart:html中创建文件对象,因为它在html_dartium.dart中保留供内部使用

factory File._() { throw new UnsupportedError("Not supported"); }
有没有其他方法来创建HTML文件对象

我见过前面提到的文件阅读器,但是这些阅读器的结果要么是字符串,要么是uint8list

  Blob response = _downloadRequest.response;
  final FileReader reader = new FileReader();

  reader.onLoad.listen((e) {
        _handleData(reader);
      });
  reader.readAsArrayBuffer(response);

参见

经过进一步的研究,我通过以下几点实现了我想要的目标:

  List<String> file_contents = ["test\n"];
  Blob blob = new Blob(file_contents, 'text/plain', 'native');

  FileSystem _filesystem = await window.requestFileSystem(1024 * 1024, persistent: false);
  FileEntry fileEntry = await _filesystem.root.createFile('dart_test.csv');
  FileWriter fw = await fileEntry.createWriter();
  fw.write(blob);
  File file = await fileEntry.file();
列出文件内容=[“测试\n”];
Blob Blob=新Blob(文件内容,'text/plain','native');
FileSystem\u FileSystem=wait window.requestFileSystem(1024*1024,持久:false);
FileEntry FileEntry=await_filesystem.root.createFile('dart_test.csv');
FileWriter fw=等待fileEntry.createWriter();
fw.write(blob);
File File=wait fileEntry.File();

虽然这可能也行得通,但经过进一步研究,我用我的答案实现了我想要的。
  List<String> file_contents = ["test\n"];
  Blob blob = new Blob(file_contents, 'text/plain', 'native');

  FileSystem _filesystem = await window.requestFileSystem(1024 * 1024, persistent: false);
  FileEntry fileEntry = await _filesystem.root.createFile('dart_test.csv');
  FileWriter fw = await fileEntry.createWriter();
  fw.write(blob);
  File file = await fileEntry.file();