V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
flyindance
V2EX  ›  PHP

PHP 模拟表单上传 oss 出错,求大佬给意见

  •  
  •   flyindance · 2018-12-06 15:00:00 +08:00 · 3405 次点击
    这是一个创建于 1939 天前的主题,其中的信息可能已经有所发展或是发生改变。

    resulted in a 400 Bad Request response:\n\n<error>\n InvalidArgument\n <message>The bucket POST contains unreco (truncated...)\n</message></error>

    如题,上为报错信息,message 内容被截断了,楼主也不知道全部 message 信息;楼主使用的是 Guzzle/client 工具,也去过阿里云找对应的错误解释,但是没找到这条 message 对应的报错解释;楼主用 postman 直接调用 oss 文件上传接口是可以的,用自己的代码,调用自己写的文件传接口也是可以的.唯独调用 OSS 上传接口出现上述错误信息.求助!

    14 条回复    2021-08-21 09:03:28 +08:00
    keepeye
        1
    keepeye  
       2018-12-06 15:26:31 +08:00
    代码呢
    flyindance
        2
    flyindance  
    OP
       2018-12-06 15:36:31 +08:00
    @keepeye
    <code>
    $file_client = new Client();
    $upload_params = $request_res["upload_params"];
    $file_client->request(
    'POST',
    $request_res["upload_url"],
    [
    'multipart' => [
    [
    "name" => "OSSAccessKeyId",
    "contents" => $upload_params["OSSAccessKeyId"]
    ],
    [
    "name" => "signature",
    "contents" => $upload_params["signature"]
    ],
    [
    "name" => "key",
    "contents" => $upload_params["key"]
    ],
    [
    "name" => "policy",
    "contents" => $upload_params["policy"],
    ],
    [
    "name" => "file",
    "contents" => $file,
    "filename" => "filename.jpg"
    ]
    ],
    ]
    );
    </code>
    flyindance
        3
    flyindance  
    OP
       2018-12-06 15:38:02 +08:00
    这是主要的上传代码,其他的都是获取参数的代码,就不贴了.
    silencefent
        4
    silencefent  
       2018-12-06 15:38:21 +08:00
    找你用的云的服务工程师慢慢查
    chanchan
        5
    chanchan  
       2018-12-06 15:58:52 +08:00
    这不是说得很清楚了吗 bad request,contains unrecognized params
    flyindance
        6
    flyindance  
    OP
       2018-12-06 16:51:45 +08:00
    @chanchan 若真是这么清除的话,也不至于来 v2 提问了,代码的参数都是跟 postman 提交的参数一样,但是 postman 可以,这段代码就是不行.
    chatfeed
        7
    chatfeed  
       2018-12-06 17:44:42 +08:00
    如果 postman 可以的话很有可能 Guzzle 使用上的问题,建议再用个抓包工具比对下 postman 和你 发起的请求之前有什么差异
    ooh
        8
    ooh  
       2018-12-06 17:50:36 +08:00
    为什么不用官方的 https://github.com/aliyun/aliyun-oss-php-sdk sdk 呢,why?why?why?
    liuxu
        9
    liuxu  
       2018-12-06 17:59:48 +08:00
    @flyindance 把最终 curl 发送的请求发出来
    349865361
        10
    349865361  
       2019-10-22 11:08:25 +08:00
    请问下你解决了么 我也遇到这个问题
    flyindance
        11
    flyindance  
    OP
       2019-11-06 23:03:33 +08:00 via iPhone
    @349865361 抱歉,才看到,这个都会时间有点久远记不得了😂
    alone88
        12
    alone88  
       2021-03-11 16:19:04 +08:00
    今天遇到了这个问题,模拟前端上传的,guzzle 上传文件时使用 file_get_contents 打开文件就可以
    alone88
        13
    alone88  
       2021-03-11 16:52:09 +08:00
    刚开始几次可以,现在又不行了。。

    The bucket POST contains unrecognized field name

    https://www.alibabacloud.com/help/zh/doc-detail/185228.htm
    realajie
        14
    realajie  
       2021-08-21 09:03:28 +08:00
    MultipartStream.php ,createElement,Content-Length 多余。
    ali oss 不需要这个。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3271 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 12:04 · PVG 20:04 · LAX 05:04 · JFK 08:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.