无需 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
EXPERTE
gefragt vor 6 Monaten21 Aufrufe
1 Antwort
0

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

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

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

profile picture
EXPERTE
beantwortet vor 6 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen