Mohd Ali
Mohd Ali

Reputation: 145

Error while get a blob from Azure storage (HTTP request) [VueJs]

I am trying to check if the blob with the path that I have exists in the Azure storage container or not.

this is my request:

let current_user_img = "https://XXXX.blob.core.windows.net/avatar/" + Img_name + ".png";

const instance = axios.create({
   timeout: 3000,
   headers: {
       "Access-Control-Allow-Origin" : "*",
       "Access-Control-Allow-Methods": "GET,POST,PUT",
       "Access-Control-Allow-Headers": "x-ms-*,content-*",
       "content-type": "application/json",
   }
});
instance .get( current_user_img )
.then(function(response) {
    console.log("User have an avatar.");
    console.log(response);
})
.catch(function(error) {
    console.log("User doesn't have an avatar.");
    console.log(error);
});

And the CORS for my storage is as follows:

ALLOWED ORIGINS: '*'
ALLOWED METHODS: 'put,get,post'
ALLOWED HEADERS: '*'
EXPOSED HEADERS: '*'
MAX AGE: 0

when I try to run the code, I faced this error:

Failed to load https://XXXX.blob.core.windows.net/avatar/XXXXXXXX.png: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

How can I solve it?

Upvotes: 0

Views: 642

Answers (1)

seebiscuit
seebiscuit

Reputation: 5063

Try adding the withCredentials: true prop to your request:

const instance = axios.create({
   withCredentials: true,  
   timeout: 3000,     
   headers: {
       "Access-Control-Allow-Origin" : "*",
       "Access-Control-Allow-Methods": "GET,POST,PUT",
       "Access-Control-Allow-Headers": "x-ms-*,content-*",
       "content-type": "application/json",
   }
});

Upvotes: 1

Related Questions