我正在使用MultipartFile
将我的图像文件发送到服务器。我知道当我使用ImagePicker
时
File ImageFile;
_openCamera() async {
var picture = await ImagePicker.pickImage(source: ImageSource.camera);
this.setState(() {
imageFile = picture;
});
}
然后像这样使用MultipartFile
request.files.add(http.MultipartFile.fromBytes('img', ImageFile.readAsBytesSync(), filename: 'photo.jpg'));
但我的问题是,我想要我的形象来自我的资产,就像从这里Image.asset('images/photo1.png');
。我有错误
A value of type 'Image' can't be assigned to a variable of type 'File'.
Try changing the type of the variable, or casting the right-hand type to 'File'.
那么,我的问题是如何使用MultipartFile
方法发送我的图像?
发布于 2020-03-26 02:02:09
首先,以字节列表的形式获取资产:
var bytes = (await rootBundle.load('images/photo1.png')).buffer.asUint8List();
然后在MultipartFile
命名构造函数中使用它:
var mpFile = http.MultipartFile.fromBytes('img', bytes, filename: 'photo.jpg');
https://stackoverflow.com/questions/60849382
复制