Home > Software engineering >  AngularJS get ETag header from $http.put request
AngularJS get ETag header from $http.put request

Time:03-29

Using an S3 MultipartUpload I need the ETag header from the AngularJS $http.put request. However I don't seem to be able to read the value. Any help is appreciated. Thanks!

$http({
    method: 'PUT',
    url: url,
    headers: {
        'Content-Type': filetype,
        'Access-Control-Expose-Headers': 'ETag'
    },
    data: part
})
.then(function(response) {
    let test1 = response.headers("ETag");
    let test2 = response.headers();
    console.log(test1, test2); // ---> null {content-length: '0'}
})
.catch(function(error) {
    console.log(error);
});

enter image description here

CodePudding user response:

Found out you need to update the CORS of the S3 Bucket:

"ExposeHeaders": [
   "ETag",
   "x-amz-meta-custom-header"
]
  • Related