[英]how to get the path from image_cropper in flutter?
I want to upload the cropped image in the server but I don't know how to get image path from the cropper.我想将裁剪后的图像上传到服务器中,但我不知道如何从裁剪器中获取图像路径。 how do I get the path from the cropper.
如何从裁剪器中获取路径。 below is my code for cropping and for uploading the cropped image.
下面是我的裁剪和上传裁剪图像的代码。
this is my code for cropping.这是我的裁剪代码。
`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;
});
}
} }
this is my code for uploading这是我的上传代码
`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);
}
} }
You can get the image path when you set it once you received the modified cropped image is received.收到修改后的裁剪图像后,您可以在设置时获取图像路径。
Hope this helps.希望这可以帮助。
try this尝试这个
var request = http.MultipartRequest( 'POST', Uri.parse("API"), ); 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.