首页 > 解决方案 > 无法将 base64 图像从颤振传递到 PHP

问题描述

PHP 代码

<?php
  $image = $_POST['image'];
  $name = $_POST['name'];
  $decoded = base64_decode($image);

  print_r($name);
  print_r($decoded);

  file_put_contents('myPath.', $decoded);
?>

出于某种原因,我通过 POST 方法传递的所有数据都是正确的,除了 base64 数据。它始终为空。

颤振代码

    List<int> imageBytes = imageFile.readAsBytesSync();
    String baseimage = base64Encode(imageBytes);
    String fileName = "PHP_Sucks.jpg";
    await http.post(
       Uri.parse("https://www.xbyte.in/Console/Image.php"),
       headers: {"Content-Type": "application/x-www-form-urlencoded"},
       body: {
          'image': baseimage,
          'name': time,
       }
    ).then((res) {
        print(res.statusCode);
        print(res.body);
    }).catchError((err) {
        print(err);
    });

图片转base64没有错误。我可以在调用 API 之前打印它,它不是 Null,但不知何故我无法在服务器上接收它。我正在尝试其他事情,我尝试通过 baseimage.substring(0, 5000000) 并且它有效。我显然没有得到图像,但是数据可以打印在服务器上,当我将其增加到 baseimage.substring(0, 10000000) 时,它又变回了 null。是因为服务器上的某种限制吗?我以前从未遇到过这样的问题。有人可以帮我吗?

服务器详情 AWS EC2,Amazon Linux AMI 2,服务器版本:Apache/2.4.48 () 服务器构建:2021 年 6 月 25 日 18:53:37

标签: phpamazon-web-servicesflutterhttpdart

解决方案


推荐阅读