jqueryajaxamazon-s3jsajaxfileuploader

Amazon S3 File Upload: throwing up 403


I've been trying to implement a multipart file upload functionality where I'm using AjaxFileUpload to achieve this.

Here's the use-case of my requirement:

  1. Hit server-A to fetch up a presigned URL, which is valid for 15 minutes.
  2. The presigned URL is basically the path where I am trying to upload the multipart file to. That path is of Amazon S3 server.

The problem is, I'm getting a 403 here, on second step.

I've checked the calls on my part, they are going fine and according to the backend, they should be working good as well.

Here's my file-upload code block:

$.ajaxFileUpload({
    url : data.preSignedUploadUrl,
    secureuri : true,
    fileElementId : 'uploadFile',
    dataType : 'json',
    contentType: "application/xml",
    success : function(data, status) {
        if(data.successful == true){
            self.sendUploadAcknowledgement(fileName);
        }else{
            $('#errorMessage').html(data.errors[0].description);
        }
    },
    error: function(err){
        console.error("Error in uploading file to S3!");
        console.log(err);
    }
});

Please note, the API calls are well-authorized and are wrapped up in their respective auth clusters.

On the basis of various solutions found over the internet, I saw that I need to change my content-type in the request. I tried putting "application/xml", "application/json" in contentType key, even tried omitting it completely.

I want to know what am I doing wrong here on frontend, or is it just the fault of the backend?


Solution

  • UPDATE: Well, the problem was there in the backend. The backend guy had messed up the permissions. Now that he has fixed his part, everything is working as expected. So, in short, to answer my question, it wasn't any fault on the frontend part, just that the backend had issues.