Cannot access file in file storage using url


  • Hi,

    My requirement is  to save some files in the file storage and make them publicly downloadable from a browser.

    I was following the tutorial at and section the section "Generate a shared access signature for a file or file share".

    uri was generated with the line Uri fileSasUri = new Uri(file.StorageUri.PrimaryUri.ToString() + sasToken);

    But when I try to access this file from a browser with this url, I get an error in a xml message

    the generated url is this -

    the error suggests that I need to have an authorization header. But I want this to be made accessible to anyone directly from the url. How can I achieve this? (without an authorization header?)



    vineri, 6 iulie 2018 15:59

Toate mesajele

  • Are specifying a policy with the filename. That's probably not what you wanted to do.

    vineri, 6 iulie 2018 19:43
  • Hi,

    Thanks for the reply. I do give a different name to the policy. Here's my code

     CloudFileDirectory rootDir = share.GetRootDirectoryReference();

                    // Get a reference to the directory we created previously.
                    CloudFileDirectory ciDir = rootDir.GetDirectoryReference("CI");
                    CloudFileDirectory documents = ciDir.GetDirectoryReference("Documents");

                    // Ensure that the directory exists.
                    if (documents.Exists())
                        // Get a reference to the file we created previously.
                        CloudFile file = documents.GetFileReference("sample.txt");

                        // Ensure that the file exists.
                        if (file.Exists())
                            // Write the contents of the file to the console window.

                            string policyName = "policy5";

                            var sharedPolicy = new SharedAccessFilePolicy{Permissions = SharedAccessFilePermissions.Read,
                                SharedAccessExpiryTime = DateTime.UtcNow.AddHours(24),
                                SharedAccessStartTime = DateTime.Now
                            var permissions = share.GetPermissions();
                            permissions.SharedAccessPolicies.Add(policyName, sharedPolicy);
                            var sasToken = file.GetSharedAccessSignature(null, policyName);
                            var uri = new Uri(file.StorageUri.PrimaryUri.ToString()+sasToken);


    vineri, 6 iulie 2018 21:15
  • Suggest you to refer similar discussion over the stackover flow  and let us know the result .

    marți, 10 iulie 2018 22:34
  • @Manukaleel:

    Just checking in if you have had a chance to see the previous response.

    joi, 12 iulie 2018 18:39