Azure Blob Storage
için tamamen yeni ve açısal istemci tarafı için CORS
'u ayarlamada sorun yaşıyorum. Bu module kullanıyorum. sasToken
başarıyla nodejs
sunucusunda oluşturdum. Azure blob depolama alanı için CORS'yi etkinleştirme
Şimdiye kadar ne yaptık şudur: AGULAR CONTROLLER İÇİNDE
:
// this is the service that generate the sasToken from the server
getService.getSasToken(filename)
.then(function (response) {
// response = {
// sasToken : "asa7sya....",
// token: "the shared key",
// account: "the storage account name"
// }
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
xhr.setRequestHeader("Content-Type","application/xml");
xhr.setRequestHeader("x-ms-version", "2013-08-15");
xhr.setRequestHeader("Authorization", response.token);
xhr.setRequestHeader("myaccount", response.account);
} else if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest();
xhr.open(method, url, true);
xhr.setRequestHeader("Content-Type","application/xml");
xhr.setRequestHeader("x-ms-version", "2013-08-15");
xhr.setRequestHeader("Authorization", response.token);
xhr.setRequestHeader("myaccount", response.account);
} else {
xhr = null;
}
return xhr;
}
var xhr = createCORSRequest('PUT', 'https://foo.blob.core.windows.net?restype=service&comp=properties');
if (!xhr) {
throw new Error('CORS not supported');
}else{
// Response handlers.
xhr.onload = function() {
alert('Response from CORS request to ' + xhr.responseText);
azureBlob.upload({
baseUrl: "https://foo.blob.core.windows.net/bar/"+filename,
sasToken: "?"+response.sasToken,
file: blobFile,
progress: function (progress) {
console.log("progress", progress);
},
complete: function (complete) {
console.log("complete", complete);
},
error: function (error) {
console.log("error", error);
},
// blockSize: // What do I put here?
})
};
xhr.onerror = function() {
alert('Woops, there was an error making the request.');
};
$.ajax({
type: "GET",
url: "../scripts/cors.xml", // local xml file
dataType: "xml",
success: function(xml){
console.log("xml", xml);
xhr.send(xml);
}
});
}
},function (error) {
console.log(error);
})
CORS.XML yukarıda
<?xml version="1.0" encoding="utf-8"?>
<StorageServiceProperties>
<Logging>
<Version>1.0</Version>
<Delete>true</Delete>
<Read>false</Read>
<Write>true</Write>
<RetentionPolicy>
<Enabled>true</Enabled>
<Days>7</Days>
</RetentionPolicy>
</Logging>
<HourMetrics>
<Version>1.0</Version>
<Enabled>true</Enabled>
<IncludeAPIs>false</IncludeAPIs>
<RetentionPolicy>
<Enabled>true</Enabled>
<Days>7</Days>
</RetentionPolicy>
</HourMetrics>
<MinuteMetrics>
<Version>1.0</Version>
<Enabled>true</Enabled>
<IncludeAPIs>true</IncludeAPIs>
<RetentionPolicy>
<Enabled>true</Enabled>
<Days>7</Days>
</RetentionPolicy>
</MinuteMetrics>
<Cors>
<CorsRule>
<AllowedOrigins>*</AllowedOrigins>
<AllowedMethods>GET,PUT,POST</AllowedMethods>
<MaxAgeInSeconds>500</MaxAgeInSeconds>
<ExposedHeaders>x-ms-meta-data*,x-ms-meta-customheader</ExposedHeaders>
<AllowedHeaders>x-ms-meta-target*,x-ms-meta-customheader</AllowedHeaders>
</CorsRule>
</Cors>
<DefaultServiceVersion>2013-08-15</DefaultServiceVersion>
</StorageServiceProperties>
kodları dayanmaktadır bu GUIDE
Herkes önce bumi yaptı:
Ancak hala bu hatayı alıyorum? Lütfen kod adamlarınızı paylaşın.
Şimdiden teşekkürler.
CORS, tüm çapraz başlangıç isteklerinden önce yapılması gereken bir uçuş öncesi HTTP SEÇENEKLERİ isteğini zorlar; bu nedenle OPTIONS'yi izin verilen bir yöntem olarak ayarlamanız gerekir. Ayrıca, < GET, PUT, POST, SEÇENEKLER AllowedMethods> 'CORS hakkındaki MDN makalesinde uçuş öncesi OPTIONS isteği hakkında bir bölüm vardır (https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS). –
@ChristoferEliasson Yine de aynı OPTIONS ekledim. – CENT1PEDE