[Vuejs]-How to resolve 403 Forbidden error when uploading to S3

0👍

getSignedUrl will work fine if you were uploading the file from an API client like Postman or a Node.js server, but as you state you are seeing a preflight check fail, I’m assuming you are using some kind of HTML form & frontend js.

From the AWS JavaScript SDK Docs regarding getSignedUrl:

Note: Not all operation parameters are supported when using pre-signed
URLs. Certain parameters, such as SSECustomerKey, ACL, Expires,
ContentLength, or Tagging must be provided as headers when sending a
request. If you are using pre-signed URLs to upload from a browser and
need to use these fields, see createPresignedPost()
.

As you are setting the ‘Expires’ param when calling getSignedUrl and are sending from the browser, you need to use createPresignedPost instead of getSignedUrl in your Lambda code.

You will then need to POST instead of PUT from the browser to S3.

NB: Remember to update your CORS rules for S3 with POST

Leave a comment