3

Can any one please provide example of how to upload to s3 bucket using presigned url. I am able to generate pre singed url but using PUT verb I am not able to upload to S3, giving below error:

Access to XMLHttpRequest at 'https://s3-bulk-files-upload.s3.ap-south-1.amazonaws.com/File1.txt?X-Amz-Expires=599&x-amz-security-token=IQoJb3JpZ2luX2VjEDAaCXVzLWVh....' from origin 'http://localhost:2020' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Thanks, Raj4ms

8
  • Can you provide additional details about how you're attempting to upload to S3? Code snippet would be helpful, as well as knowing what library you're using to interface with AWS, if any. Commented May 15, 2020 at 2:13
  • Also, have you looked at AWS's S3 CORS config documentation? Are you possibly running into this issue? Commented May 15, 2020 at 2:17
  • Header : httpOptions = { headers: new HttpHeaders ({ 'Content-Type': 'application/octet-stream', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE' }) } Commented May 15, 2020 at 8:40
  • upload(uploadFileObject: any, url: any) { return this._http.post<any>(url, uploadFileObject, this.httpOptions); } Commented May 15, 2020 at 8:42
  • File upload to S3 using pre singed url is working from console App but not working from Angular App, tried PUT and POST but getting same error: POST s3-bulk-files-upload.s3.amazonaws.com/… 403 (Forbidden) Commented May 15, 2020 at 8:46

1 Answer 1

1

Solved this issue by generating presinged url from aws-sdk javascript and upload the file using PUT operation, signed URL and added headers as below headers: new HttpHeaders({ 'x-amz-server-side-encryption': 'aws:kms', 'x-amz-server-side-encryption-aws-kms-key-id': 'arn:aws:kms:us-east-1:...' })
as S3 bucket is configured with KMS-encryption.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.