Flutter - 如何获取视频 mp4 的流响应并下载

Flutter - how to get Stream Response of Video mp4 and download it

我正在使用多部分请求,其中我 post 图像之后我收到了 video.mp4 的响应,但我不知道如何获得我尝试过的响应

       response.stream.bytetoString()  //which give me formatexception which is unexpected byte 

我不知道如何获取这个文件并在我的 flutter 应用程序中下载和播放它,这里是代码:

   Uri uri = Uri.parse(HttpLinks.localUrl);

  var stream = ByteStream(image.openRead());
  stream.cast();
  var length = await image.length();

  // here is path of image is uploading

  var request = MultipartRequest('POST', uri)
    ..files.add(
     MultipartFile(
        'file1',
        stream,
        length,
        filename:image.path,
      // contentType: MediaType('image',"jpg/png"),
      ),
    );
  var response = await request.send();// here i get response 
  if (response.statusCode == 200) {
    print('quick response is ${await response.stream.bytesToString()}');

   // here is i get exception which is 
            FormatException: Unexpected extension byte (at offset 43)

    return await response.stream.bytesToString();
  } 

请指导我该怎么做。

谢谢 Rick 指导我解决这个问题!将其设置为使用流响应获取 video.mp4 文件

  if (response.statusCode == 200) {

 final directory = await getExternalStorageDirectory();
  var file = await File('${directory.path}/video.mp4').create(recrusive: true);
 var bytes = <int>[];
response.Stream.listen{
  (newBytes){
    bytes.addAll(newBytes);
  },
   onDone: () async{
      await file.writeAsBytes(bytes);
   }
}
}
 return file;