I have a backend service which has download URL, let's say example.com/download/{filkey}
Whenever this url is called it will create google bucket CDN signed URL. And response of example.com/download/{filkey} API will have 308 (Permanent Redirect) Status code and location = {Google signed CDN URL} in its response. which means whenever I will hit example.com/download/{filkey} in browser it will be redirected to the CDN URL and image will be shown in browser and its working as expected.
But, issue occurs when I try to call example.com/download/{filkey} in JS code. It shows me No 'Access-Control-Allow-Origin' header is present
fetch('http://example.com/download/abc_file', {
method: 'GET',
mode : 'cors',
headers: {
'Authorization' : 'Bearer <Token>' // Token to validate user at backend
},
})
.then(res => {
console.log('Work Done');
console.log(res);
console.log('');
console.log(res,res.body,res.headers.get('location'),'content.res')})
.catch(err => {
console.log('Error');
console.log(err);
console.log('');
console.log(err,'content.res.err');});
I have also updated CORS policy for my google bucket. But still no luck This is my current CORS policy for google bucket
[{"maxAgeSeconds": 3600, "method": ["GET", "OPTIONS", "HEAD", "PATCH", "PUT", "POST"], "origin": ["*"], "responseHeader": ["*"]}]
I am stuck this issue from long days. I have tried lots of different ways by adding/removing headers in my request/response. It works when I add mode : no-cors in my JS request. But, I can't do that as the backend service needs the user token.
Thanks in Advance