0
votes

I'm writing a ROI calculator script at my current workplace. The calculator is designed to show how much someone would save going with our packages etc...

The form requires the person to fill out name/email/phone upon submission. That data gets parsed into JSON format and attempted to PUT to an Amazon AWS server.

I'm using the JavaScript SDK API to generate a pre-signed URL to use in my AJAX PUT request. I have tried various parameters within my request but still receive a 403 error that says - "Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 403.

When I look into the response its like this -

AccessForbidden CORSResponse: CORS is not enabled for this bucket.

If i click on the actual signed url that I console.log I get this -

SignatureDoesNotMatch

The request signature we calculated does not match the signature you provided. Check your key and signing method.

I have checked with the team that monitors this bucket, the signature and secret key are correct, and they have CORS enabled on the bucket. This is driving me crazy!

I should also add that I have tried using only GET as well, with the same error.

Here is the code of my presigned URL and AJAX request -

var s3 = new AWS.S3 ({
    accessKeyId: 'xxxxxxxxxxxxxxxxx',
    secretAccessKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
});

    var uploadPreSignedUrl = s3.getSignedUrl('putObject', {
    Bucket: 'bucket name',
    Key: 'path stuff here' + username variable + '.JSON',
    ACL: 'authenticated-read',
    ContentType: 'application/json'
});

$.ajax({
        type: "PUT",
        url: uploadPreSignedUrl,
        headers: {
            "Content-Type": "application/json"
        },
        data: JSON.stringify(userInfo),
        success: function (msg) {
            console.log(msg);
        },
        error: function (request, status, error) {
            console.log(status);
        }
    });
1
Sounds like you're not using a web server to make the requestMusa

1 Answers

0
votes

I was able to solve this... turns out the back-end team needed to enable CORS on the API Gateway AND the actual bucket itself. My pre-signed URLs were working just fine, and the AJAX call was also correct. Hope this can help someone in the future.