[英]how to get the path from image_cropper in flutter?
我想将裁剪后的图像上传到服务器中,但我不知道如何从裁剪器中获取图像路径。 如何从裁剪器中获取路径。 下面是我的裁剪和上传裁剪图像的代码。
这是我的裁剪代码。
`void _cropImage(filePath) async {
CroppedFile? _croppedFile = await ImageCropper().cropImage(
sourcePath: filePath,
aspectRatioPresets: [
CropAspectRatioPreset.square,
CropAspectRatioPreset.ratio3x2,
CropAspectRatioPreset.original,
CropAspectRatioPreset.ratio4x3,
CropAspectRatioPreset.ratio16x9
],
uiSettings: [
AndroidUiSettings(
toolbarTitle: 'Cropper',
toolbarColor: Colors.deepOrange,
toolbarWidgetColor: Colors.white,
initAspectRatio: CropAspectRatioPreset.original,
lockAspectRatio: false),
IOSUiSettings(
title: 'Cropper',
),
],);
// compressFormat: ImageCompressFormat.jpg);
// cropImagePath.value = croppedFile!.path;
if (_croppedFile != null) {
setState(() {
imageFile = _croppedFile.path;
});
}
}
这是我的上传代码
`uploadImage() async {
var request = http.MultipartRequest(
'POST', Uri.parse('http://hsdgfddf/api/examples/add'));
request.files.add(await http.MultipartFile.fromPath(
'picture', croppedfile!.path));
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
print(await response.stream.bytesToString());
}
else {
print(response.reasonPhrase);
}
}
收到修改后的裁剪图像后,您可以在设置时获取图像路径。
希望这可以帮助。
尝试这个
var request = http.MultipartRequest('POST', Uri.parse("API"), );
Map<String, String> headers = {"Content-type": "multipart/form-data"};
request.files.add(
http.MultipartFile(
'pic' //picture_index,
selectedImage.readAsBytes().asStream(),
selectedImage.lengthSync(),
filename: croppedImage.path.split('/').last,
),
);
request.headers.addAll(headers);
print("request: " + request.toString());
var res = await request.send();
http.Response response = await http.Response.fromStream(res);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.