无需 AWS Lambda 即可将通过AWS API Gateway将文件上传到 S3 的

0

【以下的问题经过翻译处理】 我已创建一个AWS API Gateway,使用AWS服务集成将文件上传到S3。API在后端代码或Postman中运行正常,但当我尝试从Vue.js或任何JavaScript中的代码调用API时,出现CORS错误。我已启用了CORS设置,并使用curl进行了测试,它返回了CORS头部在响应中。

根据CloudWatch的记录,预检请求(preflight)调用失败,返回500错误。

2022-05-25T13:38:14.343+05:30 (18e87194-3f4d-4ecf-b8fc-e6b1069eb878) Method request body before transformations: [Binary Data]

2022-05-25T13:38:14.343+05:30 (18e87194-3f4d-4ecf-b8fc-e6b1069eb878) Execution failed due to configuration error: Unable to transform request

我的VUE代码:

const article = "Vue POST Request Example" ; const headers = { "Content-Type":'text/plain' }; axios.put("https://ivdfgjilc5.execute-api.ap-southeast-1.amazonaws.com/devv1/vxpoc-es-appsearch/tests3/tryfinal44.txt", article,headers) .then((response) => { console.log(response) }) .catch(error => { this.errorMessage = error.message; console.error("There was an error!", error); });
profile picture
专家
已提问 5 个月前18 查看次数
1 回答
0

【以下的回答经过翻译处理】 问题并不是CORS。实际问题是预检请求(preflight)返回了500错误,正如我在问题中所提到的。

error Execution failed due to configuration error: Unable to transform request

我们发现在API设置中的二进制媒体配置是导致问题的原因,在我的情况下。我已将其更改为image/png,然后正常工作

profile picture
专家
已回答 5 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则