I am using an HTTP request to upload an image to the Azure storage, It's work for me when the CORS of the storage account is general, for example:
allowed origins: *
allowed methods: 7 selected (which all options)
allowed headers: *
exposed headers: *
max age: 0
And in my Http request (sing axios):
headers: {
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Headers": "*",
"Content-Type": "image/png",
"x-ms-date": currentDate,
"x-ms-version": ""2017-11-09"",
"x-ms-blob-type": "BlockBlob",
}
It's work with me and image uploaded, but when I modified the CORS to add some constraints, it does not work. for example:
allowed origins: https://XXXXXXXX.blob.core.windows.net/
allowed methods: 7 selected (which all options)
allowed headers: Authorization,x-ms-*
exposed headers: x-ms-meta-*
max age: 3600
And in my HTTP request (sing axios):
headers: {
"Access-Control-Allow-Origin" : "https://XXXXXXXX.blob.core.windows.net/",
"Access-Control-Allow-Methods": "PUT,GET,PATCH,POST,HEAD,DELETE,MERGE,OPTIONS",
"Access-Control-Allow-Headers": "Authorization,x-ms-*,content-*",
"Content-Type": "image/png",
"x-ms-date": currentDate,
"x-ms-version": ""2017-11-09"",
"x-ms-blob-type": "BlockBlob",
}
I faced two Error messages:
OPTIONS https://XXXXXXXXXX.blob.core.windows.net/user-avatar/XXXXXXXXXXXXXXXXXXXXXXXX 403 (CORS not enabled or no matching rule found for this request.)
Failed to load https://XXXXXXXXXX.blob.core.windows.net/user-avatar/XXXXXXXXXXXXXXXXXXXXXXXX: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
How should I solve the problem?