为什么form表单直传会先进行一次option请求呢?
ppjjhh opened this issue · 4 comments
错误场景:vue项目,使用vditor( https://b3log.org/vditor/ )编辑器 upload 图片。
第一次请求是option,响应是200。然后才开始POST上传,然后400 Bad Request
我使用贵公司提供的简单实例上传( https://cloud.tencent.com/document/product/436/9067 ),直接用html表单,能上传成功。
响应信息:
<?xml version='1.0' encoding='utf-8' ?>
<Error>
<Code>InvalidArgument</Code>
<Message>Invalid Argument</Message>
<Resource>panda-*********.cos.ap-guangzhou.myqcloud.com/dir/Screen Shot 2022-05-10 at 5.25.08 PM.png</Resource>
<RequestId>NjI5YzllYjNfYTkyZTJjMGJfMmE0MmVfNjAyY2Iz</RequestId>
<TraceId>OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OTI5MWRkM2I1ZDU3ZWE5Y2YzNDYzZTEzY2JlMjU3NDQ0MmYwMzBmZWUzZjBmOTFhNWFhYjgwYjQ3NmM5NDkzOTg=</TraceId>
</Error>
请求携带的payload,哪个参数无效?希望能把报错信息表示的更加明确。
------WebKitFormBoundaryxUlKftlwNPRp8vPf
Content-Disposition: form-data; name="key"
dir/Screen Shot 2022-05-10 at 5.25.08 PM.png
------WebKitFormBoundaryxUlKftlwNPRp8vPf
Content-Disposition: form-data; name="Signature"
q-sign-algorithm=sha1&q-ak=AKIDY6yGOVGr8u46ML9bBgL3WcN1X0QZ9qNMxpLlA7aVQfR992mUdKSQL9eM8swJw9kW&q-sign-time=1654431410.476;1654432310.476&q-key-time=1654431410.476;1654432310.476&q-header-list=&q-url-param-list=&q-signature=16a4a93a3a51c73f666889de7c49e12430909dc0
------WebKitFormBoundaryxUlKftlwNPRp8vPf
Content-Disposition: form-data; name="x-cos-security-token"
50rO0odiQYCsccUQg6PeES42nMW9aTGaf92e4625d439db324c2e71a365241427Mmj7-dlgGaJPhPJi9eqGzx08b_UpVg3f0Zh8GknN2fvgrGge6PeMY_Z3i2k2pqAqliR9ImdwsszAs-U7QTMRBZCMlZug9yJJ4TesPD65JeZkrWOLm_w7iRyDcfd-PQ6OTPDKIaVOkSUtQ6fL1V-5hojKqbF-E-fRiLv2NTqXHEm5r5zOIGJKnu5sVRZ0Bv_K-vjYahhIWj2NkOzGqIQHylVHXlt0LPLevGoUPApO2fVX8uqVL9RyJ2BKjlWuJ4f6J-79TAceUZzWy4Mb6zqxOhv7TWOPEM5jcc1TvekubAyKUrBPziIc0PiWTWU_AY4PUsFGpMFHGGEKbA30V5j4UkBnXs4cVBrL653WmawMi1ynm7BB3xznzMmjkfzwlItxGZUzryo4f362kYXlQ_9Dnu4Iz7TDAr3ho2QKihVkajsFZLtLMQ1o0BVd9x1W0YDCdNCdCIVIeh2uMaz60TII8Yd1z0RXYezkmJouNzA2R7X_6IGX4unTE2frCfqvnwc__YO0KbVI7aH6BLzN8Wt1ftnN-KntpgynZBiZ_7HIQvfdp6QZKxR-7gU0c3rOHXq3JYrv-P8rpVextWPzU69v1w_a0XHnK4Q-u9F5izaohfnY9nPjRyKxmwK-TVYbQvxqiLQ441VS3YCDW4IoXMOtqBXd1qeXJM754JRFXylbMZbVVaoUVhGgdFG4HdFVF3UibAYgt_9sQiapW6aN01qhrV-mFTslTK5dg898T_4b7ktrQNyPP2xKi0pbeswPrdZqb9ib5GMIZPx_zDfcpgHRwB60vI9u-llHYJ8Oc3-sQKf-3T2ZhZ396jtfqbRP3b818YlVxBhdcyMJc1EipmNt0PP3vFFDM4P6IeKZfG7fHRcChwHzTYTidVFMPY6FsnT-LDAWiRWzeu284W-0cQtS-ug0VNAKxYL6_vtHX7ean76NmEOqpwQ4u_JAmYycYFn_699KlVeseJ6PmZAQoEi-AsrMNwz35BzOav4LxXACHNv0oIpINe2W85Bd-h1WMFqd
------WebKitFormBoundaryxUlKftlwNPRp8vPf
Content-Disposition: form-data; name="file[]"; filename="Screen Shot 2022-05-10 at 5.25.08 PM.png"
Content-Type: image/png
------WebKitFormBoundaryxUlKftlwNPRp8vPf--
你好,options请求是跨域请求时发起的预检请求;从报错日志看直传时没有上送Authorization和SecurityToken参数,请参考文档中以下代码片段相关逻辑:
xhr.setRequestHeader('Authorization', auth);
SecurityToken && xhr.setRequestHeader('x-cos-security-token', SecurityToken);
好的,非常感谢。