AWS API Gatway to upload File To S3 without AWS Lambda
Hi i have create 1 aws api gateway which post file to s3 using aws service integration , api works fine from backend code or postman , but when i am trying to post the api from vue js or any java script , its thorn the CORS error , i have enabled the cors setting , and tested using curl its return CORS header in response .
As per Cloud watch preflight called is failing with 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`
my vue js code
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);
});
any suggestion on this will be helpful
hi we able to solve this issue , after discussing with aws support , as problem was not with cors. actual problem was with preflight request was giving 500 which i was mentioned in question . with this error
error Execution failed due to configuration error: Unable to transform request
we figure out Binary media in api setting / was causing the problem in my case , i have changed to image/png and its started working . Thanks for all help.
I am not sure what is causing the error, but why are you uploading through API Gateway? Why not upload directly to S3? Just generate a pre-signed upload URL using a Lambda function and upload directly using that URL. It will reduce the latency and also will bypass API Gateway's 10MB payload limit.
Did you enable CORS for both API Gateway and S3?
CORS docs:
yes i enabled the CORS for both , i able to solve it . posting the answer below .
Relevant questions
Internal Server Error from API Gateway when sending queries through gateway to Lambda function connected to RDS database
asked 3 months agoCreate a Post and Get API as an Amazon S3 proxy in API Gateway
asked an hour agoAWS Api Gateway: how to expose new services automatically?
asked 4 months agoAWS API Gateway cannot connect to S3 bucket?
asked 3 years agoUploading greater than 6 MB file to S3 through API Gateway results in Request too long error, Is that expected ?
asked 3 months agoPinpoint Creating Segment API upload file
asked 2 months ago403 Forbidden Error when calling an AWS API Gateway in Python
asked 3 years agoFile corrupted after upload to S3 using Lambda and API Gateway
asked 2 years agoAWS API Gatway to upload File To S3 without AWS Lambda
Accepted Answerasked a month agoBinary uploads to API Gateway Proxy with Lambda Integration
Accepted Answerasked 5 years ago
hi i have requirement where i wanted to send event data direct to s3 as text file . so i do not have any file to upload. its actually text data which will store as file . but still i will look ur suggestion .