I'm creating a website that needs to be able to retrieve files from an Azure Storage Container that I have and I'm having difficulty actually retrieving any files.
So the container's Access Policy is set to the Private (no anonymous access)
value since I don't want just anyone to be able to access it. I then went into CORS settings and created a new CORS rule. For now I setup the options as follows:
ALLOWED ORIGINS == *
ALLOWED METHODS == GET
ALLOWED HEADERS == *
EXPOSED HEADERS == *
MAX AGE == 10000
I think I'm supposed to put my website into the ALLOWED ORIGINS
field to restrict access to only my website, but for now I'm leaving it just with an *
to get this started.
So I think this should allow me to get
blobs from my container...
Here is how I'm attempting to retrieve the files in PHP
$response = file_get_contents("https://<accountname>.blob.core.windows.net/<containername>/SomeSimpleFile.txt");
print_r($response );
But I don't get the contents of the file back, instead I get the following error messages:
[01-Aug-2018 12:58:35 America/Los_Angeles] PHP Warning: file_get_contents(https://<accountname>.blob.core.windows.net/<containername>/SomeSimpleFile.txt): failed to open stream: HTTP request failed! HTTP/1.1 404 The specified resource does not exist.
in D:\home\site\wwwroot\index.php on line 30
If I go back into the Azure Portal and change the container's access policy to Blob (anonymous read access for blobs only)
then I am able to get the file using the above PHP code. So I know the url I'm using for the file is correct. It seems I have set something wrong in the CORS settings. Or maybe it's something else.
Any help I can get on this is appreciated.