📅  最后修改于: 2022-03-11 15:03:01.982000             🧑  作者: Mango
Future> uploadfile(File file) async {
var stream = new http.ByteStream(DelegatingStream(file.openRead()));
var length = await file.length();
var uri = Uri.parse("Enter your URL");
var request = new http.MultipartRequest("POST", uri);
var multipartFile = new http.MultipartFile('data', stream, length, filename: basename(file.path));
request.files.add(multipartFile);
await request.send().then((response) {
response.stream.transform(utf8.decoder).listen((value) {
file.delete();
print(value);
});
}).catchError((e) {
print(e);
});
}