gpt4 book ai didi

php - 字段中格式错误的 Unicode 代码序列

转载 作者:搜寻专家 更新时间:2023-10-31 21:23:03 24 4
gpt4 key购买 nike

我正在尝试使用 POST 表单将浏览器上传到我的 s3 存储桶。我正在使用 eddturtle/direct-upload生成策略和签名。这是我的代码:

$upload = new Signature(
self::S3_KEY,
self::S3_SECRET,
self::S3_BUCKET,
self::S3_REGION
);

并使用 $upload->getFormInputsAsHtml() 方法生成 html。正在生成这样的 html

<form action="//s3.amazonaws.com/bucket" method="POST" enctype="multipart/form-data" class="upload-form">
<input type="hidden" name="Content-Type" value="">
<input type="hidden" name="acl" value="public-read">
<input type="hidden" name="success_action_status" value="201">
<input type="hidden" name="policy" value="eyJleHBpcmF0aW9uIjoiMjAxNy0wMi0xNVQxMzowNDozOFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJ0YWdmaSJ9LHsiYWNsIjoicHJpdmF0ZSJ9LFsic3RhcnRzLXdpdGgiLCIka2V5IiwiIl0sWyJzdGFydHMtd2l0aCIsIiRDb250ZW50LVR5cGUiLCIiXSxbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwwLDUyNDI4ODAwMF0seyJzdWNjNzX2FjdGlvbl9zdGF0dXMiOiIyMDEifSx7IngtYW16LWNyZWRlbnRpYWwiOiJBS0lBSkhGS0hKMklLNjZTVFA0QVwvMjAxNzAyMTVcL3VzLWVhc3QtMVwvczNcL2F3czRfcmVxdWVzdCJ9LHsieC1hbXotYWxnb3JpdGhtIjoiQVdTNC1ITUFDLVNIQTI1NiJ9LHsieC1hbXotZGF0ZSI6IjIwMTcwMjE1VDA3MDQzOFoifV19">
<input type="hidden" name="X-amz-credential" value="AKIAJHFKHJ2IK66STP4A/20170215/us-east-1/s3/aws4_request">
<input type="hidden" name="X-amz-algorithm" value="AWS4-HMAC-SHA256">
<input type="hidden" name="X-amz-date" value="20170215T070438Z">
<input type="hidden" name="X-amz-signature" value="e9d30613e4fcab8fec3fe75c4ce2969bb6497d83af7cca7f9ea6a1c0738844c5">
<input type="hidden" name="key" value="${filename}">
</form>

但是在提交表单后,我从 s3 收到了这个错误

<Error>
<Code>InvalidArgument</Code>
<Message>Malformed Unicode code sequence in the field.</Message>
<ArgumentName>formField</ArgumentName>
<RequestId>46E52494FC98ED76</RequestId>
<HostId>
Qk/g94sJSfVicIxPb3oFN0nO1EVCvxy8YzBQjRKyKpATZZmX1VjlDK+zWfvidhZl5vuemZyuKg0=
</HostId>
</Error>

示例请求负载

------WebKitFormBoundaryVGEGWkAW5d70u2rp Content-Disposition: form-data; name="image"; filename="shop-small.png" Content-Type:image/png

------WebKitFormBoundaryVGEGWkAW5d70u2rp Content-Disposition: form-data; name="Content-Type"

------WebKitFormBoundaryVGEGWkAW5d70u2rp Content-Disposition: form-data; name="acl"

private------WebKitFormBoundaryVGEGWkAW5d70u2rp Content-Disposition: form-data; name="success_action_status"

201------WebKitFormBoundaryVGEGWkAW5d70u2rp Content-Disposition: form-data; name="policy"

eyJleHBpcmF0aW9uIjoiMjAxNy0wMi0xNVQxOToxMzo1NVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJ0YWdmaSJ9LHsiYWNsIjoicHJpdmF0ZSJ9LFsic3RhcnRzLXdpdGgiLCIka2V5IiwiIl0sWyJzdGFydHMtd2l0aCIsIiRDb250ZW50LVR5cGUiLCIiXSxbImNvbnRlbnQtbGVuZ3RoLXJhbmdlIiwwLDUyNDI4ODAwMF0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiIyMDEifSx7IngtYW16LWNyZWRlbnRpYWwiOiJBS0lBSkhGS0hKMklLNjZTVFA0QVwvMjAxNzAyMTVcL3VzLWVhc3QtMVwvczNcL2F3czRfcmVxdWVzdCJ9LHsieC1hbXotYWxnb3JpdGhtIjoiQVdTNC1ITUFDLVNIQTI1NiJ9LHsieC1hbXotZGF0ZSI6IjIwMTcwMjE1VDEzMTM1NVoifV19------WebKitFormBoundaryVGEGWkAW5d70u2rp Content-Disposition: form-data; name="X-amz-credential"

AKIAJHFKHJ2IK66STP4A/20170215/us-east-1/s3/aws4_request------WebKitFormBoundaryVGEGWkAW5d70u2rp Content-Disposition: form-data; name="X-amz-algorithm"

AWS4-HMAC-SHA256------WebKitFormBoundaryVGEGWkAW5d70u2rp Content-Disposition: form-data; name="X-amz-date"

20170215T131355Z------WebKitFormBoundaryVGEGWkAW5d70u2rp Content-Disposition: form-data; name="X-amz-signature"

1c28fb88fc0b1317df11b7f566fe39eaac9b8cba012b8fef80448e93767f2677------WebKitFormBoundaryVGEGWkAW5d70u2rp Content-Disposition: form-data; name="key"

testfile------WebKitFormBoundaryVGEGWkAW5d70u2rp--

我不知道问题出在哪里,也不知道如何解决。我经历过的每个例子都使用类似的过程。提前致谢。

最佳答案

我终于修好了。虽然我仍然不知道是什么导致了这个问题。我没有使用 $upload->getFormInputsAsHtml(); 来获取表单内容,而是使用了 $s3Policy = $upload->getFormInputs(); 来获取策略和单独分配给预先编写的 html。

<form :action="aws_url" method="POST" enctype="multipart/form-data">

<input type="hidden" name="Content-Type" :value="s3Policy.content_type" />
<input type="hidden" name="acl" :value="s3Policy.acl" />
<input type="hidden" name="success_action_status" :value="s3Policy.success_action_status" />
<input type="hidden" name="policy" :value="s3Policy.policy" />
<input type="hidden" name="X-amz-credential" :value="s3Policy.credential" />
<input type="hidden" name="X-amz-algorithm" :value="s3Policy.algorithm" />
<input type="hidden" name="X-amz-date" :value="s3Policy.date" />
<input type="hidden" name="X-amz-signature" :value="s3Policy.signature" />
<input type="hidden" name="key" :value="s3Policy.key" />
<input type="file" name="file">
<input type="submit" value="Upload">

</form>

这可能是由我前端的 vuejs 引起的,但 html 在开发控制台中看起来不错。

关于php - 字段中格式错误的 Unicode 代码序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42242832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com