[英]Flutter (dart) file upload, progress bar - file upload stream not give back data during upload
在文件上傳到服務器時,我想顯示上傳狀態。 在 ios,我沒有來自流的信息。 我的代碼(部分):
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");
}
控制台打印:
顫振:1
顫振:2
顫振:視頻上傳
顫振:49 - 這來自流
你有什么主意嗎?
你可以這樣解決這個問題:
final stream = await request.send();
print(stream.statusCode);
final response = await http.Response.fromStream(stream);
那么你可以像下面這樣解析響應:
final jsonResponse = json.decode(response.body);
print("response is : $jsonResponse");
或者,如果它是Future<Response>
的實例,則可以立即將其分配給_response
變量,如下所示:
_response = await http.Response.fromStream(stream);
請注意,我有這樣的導入:
import 'package:http/http.dart' as http;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.