kushagra mishra
kushagra mishra

Reputation: 1

PUT call not working for s3 bucket using a AWS GATEWAY api?

admin:1 Access to XMLHttpRequest at '/dev/directjobfinder/listing.json' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

IT'S WORKING FINE IN POSTMAN BUT WHEN IM USING AXIOS.PUT THEN IT'S GIVING THE ABOVE ERROR SOMEONE PLEASE HELP I'M STUCKED FROM LAST 2 DAYS

I HAVE DONE Access-Control-Allow-Headers : * Access-Control-Allow-Origin : *'

CORS CONFIG file of S3 bucket [ { "AllowedHeaders": [ "*" ], "AllowedMethods": [ "GET", "PUT" ], "AllowedOrigins": [ "*" ], "ExposeHeaders": [] } ]

EDIT : ERROR DETAILS SCREENSHOT

Upvotes: 0

Views: 368

Answers (3)

Ramamoorthy P
Ramamoorthy P

Reputation: 1

make sure OPTIONS returns 200 ok by running the curl command.

curl -X OPTIONS -H "Origin: ORIGIN_URL" --verbose API_ENDPOINT

If not then run the below command

aws apigateway update-integration --rest-api-id YOUR_REST_ID --resource-id YOUR_RESOURCE_ID --http-method OPTIONS --patch-operations op='replace',path='/contentHandling',value='CONVERT_TO_TEXT'

and dont forget to redeploy the API

for more details: AWS API gateway error while making OPTIONS request

Upvotes: 0

kushagra mishra
kushagra mishra

Reputation: 1

ANSWER : I was calling the api using axios and my method was POST but the problem was in the response header , I was passing a javascript object as application/json , there resides the problem itself i just change it to tex/plain then it works fine .

Upvotes: 0

Alex Chadyuk
Alex Chadyuk

Reputation: 1596

CORS config on the S3 bucket should allow OPTIONS method for a preflight request.

Upvotes: 0

Related Questions