我已经使用下面的代码使用.net REST API在multipart / form-data中上传图像。在邮递员中使用时,我可以成功上传图像,但在抖动中,我不会得到异常输出。
file = await ImagePicker.pickImage(source: ImageSource.camera);
String fileName = file.path.split('/').last;
var stream = new http.ByteStream(DelegatingStream.typed(file.openRead()));
var length = await file.length();
var uri = Uri.parse(phpEndPoint);
var request = new http.MultipartRequest("POST", uri);
var multipartFile = new http.MultipartFile('Uploading', stream, length,
filename: basename(file.path));
//contentType: new MediaType('image', 'png'));
request.files.add(multipartFile);
var response = await request.send().timeout(const Duration(seconds: 100));
print(response.statusCode);
response.stream.transform(utf8.decoder).listen((value) {
print(value);
});```
Actual Output:
{
“响应”:{
"Success": "False",
"message": "Image parsing failed"
}
}
Excepted Output:
{
“响应”:{
"Success": "true",
"message": "Image Uploading success"
}
}