尝试通过http或Dio上传适用于图像和文档的视频时出现错误。 我尝试使用那些功能 http和Dio。 拜托,有人遇到过这样的问题吗?
//This function uses http
void uploadVideo(String fpath) async {
var uri = Uri.parse('http://192.168.0.3:51971/Home/uploadFile');
var request = new http.MultipartRequest("POST", uri);
var multipartFile = await http.MultipartFile.fromPath("files", fpath);
request.files.add(multipartFile);
var response = await request.send();
response.stream.transform(utf8.decoder).listen((value) {
print(value);
});
if(response.statusCode==200){
print("Video uploaded");
}else{
print("Video upload failed");
}
}
//And this uses Dio
void uploadViaDio(String filePath) async
{
try {
var image = await FilePicker.getFile();
String fileName = basename(image.path);
print(image);
FormData formData =
new FormData.from({"files": new UploadFileInfo(image , fileName)});
Response response =
await Dio().post('http://192.168.0.3:51971/Home/uploadFile', data: formData);
print("File upload response: $response");
print(response.data['message']);
} catch (e) {
print("Exception Caught: $e");
}
}