简体   繁体   中英

Flutter (dart) file upload, progress bar - file upload stream not give back data during upload

At file upload to server, I would like to display the upload status. At ios, I don't have information from the stream. My code(part):

var multipartFile = await MultipartFile.fromPath("video", file);
request.files.add(multipartFile);
request.fields.addAll(queryParameterss);

print('1');

_response = await request.send();

print('2');

_response.stream.listen((value) {
  print(value.last);
});

if(_response.statusCode==200){
  print("Video uploaded");
}else{
  print("Video upload failed");
}

The console prints:

flutter: 1

flutter: 2

flutter: Video uploaded

flutter: 49 - this come from stream

Do you have any idea?

You could tackle the issue like this:

final stream = await request.send();

print(stream.statusCode);

final response = await http.Response.fromStream(stream);

then you could parse the response like below:

final jsonResponse = json.decode(response.body);

print("response is : $jsonResponse");

or you can straight away assign it to your _response variable if it's an instance of Future<Response> like this:

_response = await http.Response.fromStream(stream);

Note that I have an import like this:

import 'package:http/http.dart' as http;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM