none
Cannot access file in file storage using url

    Întrebare

  • 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 https://docs.microsoft.com/en-us/azure/storage/files/storage-dotnet-how-to-use-files#develop-with-file-storage 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 - https://storage01us.file.core.windows.net/documents/CI/Documents/sample.txt?sv=2018-03-28&sr=f&si=policy5&sig=zq45L4I27jP4G353Ed3dDzgKu83dpmtIdMO5DoHFzQs%3D

    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?)

    Thanks,

    Manuka.

    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
    Moderator
  • 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.
                            Console.WriteLine(file.DownloadTextAsync().Result);

                            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);
                            Console.WriteLine(uri.ToString());


                        }
                    }

    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
    Moderator
  • @Manukaleel:

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

    joi, 12 iulie 2018 18:39
    Moderator