将python请求转换为httpFlutter

6g8kf2rb  于 2021-07-14  发布在  Java
关注(0)|答案(1)|浏览(228)

我的python代码如下:

files = {
    'image_url': (None, ''),
    'image_content': (None, ''),
    'filename': (None, ''),
    'h1': (None, 'en'),
    'bih': (None, '179'),
    'biw': (None, '1600'),
    'encoded_image': (None, open(file,'rb')),
}
response = requests.post('https://www.google.co.in/searchbyimage/upload', files=files, allow_redirects=True)

curl命令无效 curl -F encoded_image=@/path/to/image.jpg https://www.google.de/searchbyimage/upload 如何将此代码转换为flatterhttp或任何其他包(如dio)?

kkbh8khc

kkbh8khc1#

导入 dio 包裹。

Future<String> uploadFile(File file) async {
    String fileName = file.path.split('/').last;
    FormData formData = FormData.fromMap({
        // your other data here
        "file":
            await MultipartFile.fromFile(file.path, filename:fileName),
    });
    response = await dio.post("https://www.google.co.in/searchbyimage/upload", data: formData);
    return response.data;
}

相关问题