【发布时间】:2021-06-02 10:52:56
【问题描述】:
我有一个颤振应用程序,它使用 asp.net rest api 选择音频文件并将其上传到服务器。
我的flutter代码如下
uploadFile() async {
print(file.path);
var postUri = Uri.parse("http://192.168.1.100:5041/api/fileup/up");
var request = new http.MultipartRequest("POST", postUri);
request.fields['user'] = 'blah';
request.files.add(new http.MultipartFile.fromBytes('file', await File.fromUri(Uri.parse(file.path)).readAsBytes(),contentType: MediaType('audio','mp3')
));
request.send().then((response) {
if (response.statusCode == 200) {
print("Uploaded!");
}else{
print(response.reasonPhrase);
}
});
}
上述颤振代码的我的 file.path 值为“/data/user/0/com.mydomain.myappname/cache/file_picker/Over_the_Horizon.mp3”,它是从文件选择器返回的。
我可以使用邮递员上传文件,但颤动代码给我 500:内部服务器错误
尝试了几个在堆栈溢出时发现的代码,都给了我同样的错误
【问题讨论】:
-
你好,我的情况和你一样,你用
dio包后效果如何,还有问题吗?
标签: flutter asp.net-web-api file-upload