0

When I try to get a signed url through upload for image upload / jpg always give me error, help plz

def call
credentials = Aws::Credentials.new(secrets_key, access_key)
    resource = Aws::S3::Resource::new(region: 'sa-east-1', credentials: credentials)
    object = resource.bucket(Rails.application.secrets.aws_bucket_for_uploads).object(file_name)
    params = { acl:'public-read' }

    object.presigned_url(:put, params)
  end

and my front

response_success(urlSigned, e, typeImage) {
  this.setState({ uploading : true });
  var xhr = new XMLHttpRequest();

  xhr.upload.onprogress = function(e){
    if (e.lengthComputable){
      var percentComplete =  Math.ceil((e.loaded / e.total) * 100);
      this.setState({ uploadedPercent : percentComplete });
    }
  }.bind(this);

 xhr.open("PUT", urlSigned);
 xhr.setRequestHeader("Cache-Control", "public,max-age=3600");
 xhr.setRequestHeader('x-amz-acl', 'public-read');
 xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
 xhr.setRequestHeader("Access-Control-Allow-Headers", "X-Requested-With");
 xhr.setRequestHeader("Access-Control-Allow-Headers", "Content-*");
 xhr.setRequestHeader("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");


 xhr.onload = function() {
   if (xhr.status === 200) {
     console.log("file uploaded success " + data.getUrl);
     return validateDocument(clientId, 'FIRST_ACCESSS_DOCUMENTS_STEP', data.getUrl, user, typeImage)
       .then(response => this.response_success(response.data));

       this.setState({showFirstButton: false});
       this.setState({imageUrl : data.getUrl, uploading : false});
   }
 }.bind(this);
 xhr.onerror = function() {
   this.setState({ uploading : false });
 }.bind(this);
 xhr.send(e);

}

Please, contact your opinion, I tried to set acl, content_type, change as the Amazon report, and there always comes the same error, x-amz-acl

<Error>
<Code>AccessDenied</Code>
<Message>There were headers present in the request which were not signed</Message>

</Error>
testing
  • 1
  • 2

1 Answers1

1

The error code tells you what exactly is the problem: Your HTTP request has additional headers that were not present in the signing request.

Kingz
  • 5,086
  • 3
  • 36
  • 25