I'm trying to upload a file for the azure storage emulator in a react application.
I'm using https://aka.ms/downloadazurestoragejs
This is my code:
const azure = require('./azure-storage.blob.js');
const devStoreCreds = azure.generateDevelopmentStorageCredentials();
let blobService = azure.createBlobService(devStoreCreds);
const serviceProperties = {
Cors: {
CorsRule: [{
AllowedOrigins: ['*'],
AllowedMethods: ['POST', 'PUT'],
AllowedHeaders: ['*'],
ExposedHeaders: ['*'],
MaxAgeInSeconds: 200
}]
}
};
blobService.setServiceProperties(serviceProperties, function(error, result,
response) {
if (error) {
alert('service failed, open browser console for more detailed
info.');
}
});
blobService.createContainerIfNotExists('mycont',function(error, result,
response) {
if (error) {
alert('Container Failed created');
}
else{
let blockSize = file.size > 1024 * 1024 * 32 ? 1024 * 1024 * 4 : 1024
* 512;
const options = {
blockSize : blockSize
};
blobService.singleBlobPutThresholdInBytes = blockSize;
let finishedOrError = false;
let speedSummary =
blobService.createBlockBlobFromBrowserFile("mycont", file.name, file,
options, function(error, result, response) {
finishedOrError = true;
if (error) {
alert('Upload failed, open browser console for more detailed
info.');
console.log(error);
} else {
alert('ok.');
}
});
}
});
but I'm getting this error:
Failed to load resource: the server responded with a status of 403 (CORS not enabled or no matching rule found for this request.)
Failed to load http://127.0.0.1:10000/devstoreaccount1/?comp=properties&restype=service: 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:3000' is therefore not allowed access. The response had HTTP status code 403.