【问题标题】:Convert python requests to http flutter将python请求转换为http颤振
【发布时间】:2021-07-04 13:56:18
【问题描述】:

我有一个类似的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

如何将此代码转换为 Flutter HTTP 或任何其他包(如 dio)?

【问题讨论】:

    标签: python flutter http python-requests


    【解决方案1】:

    导入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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-17
      • 1970-01-01
      • 2020-11-09
      • 1970-01-01
      • 1970-01-01
      • 2020-10-02
      • 1970-01-01
      相关资源
      最近更新 更多