【以下的问题经过翻译处理】 我已创建一个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); });