0

This has taken a while to track down.

I have this code that works

            CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
        var uploadedContainer = cloudBlobClient.GetContainerReference("uploadedfiles");
        uploadedContainer.CreateIfNotExists(new BlobRequestOptions() { RetryPolicy = new NoRetry() }, null);

        var directory = uploadedContainer.GetDirectoryReference(path);
        CloudBlockBlob cloudBlockBlob = directory.GetBlockBlobReference($"dave.pdf");

but if I change the last line to the following my blob trigger blows up in the function

CloudBlockBlob cloudBlockBlob = directory.GetBlockBlobReference($"{Guid.NewGuid().ToString()}.pdf");

Very frustrating. The error is :

[18/10/2019 14:37:36] An unhandled exception has occurred. Host is shutting down. [18/10/2019 14:37:36] Microsoft.WindowsAzure.Storage: Server encountered an internal error. Please try again after some time.

Great use of error message - thanks!

I want to be able to use a guid here. The docs for naming conventions seem to say this is a legal situation found here

someone must have an idea!

the following filenames work

"s-a" "dave.pdf" $"{Guid.New().ToString()}"

This does not work $"{Guid.New().ToString()}.pdf"

John Nicholas
  • 4,778
  • 4
  • 31
  • 50
  • Why do you need to use `Path.GetFileName`? – Chris Oct 19 '19 at 18:01
  • its there from me trimming down the problem. I have reproduced without it (I have a github issue without it! i just forgot to update here!) sorry – John Nicholas Oct 22 '19 at 19:11
  • I have a similar scenario, I have a blob storage that can receive any file name, then it moves to a new one using a new Guid as part of the filename. Azure function is abending just like yours, the difference is that it abends with both azure storage emulator and actual Azure Storage blob. I ended up using half f the guid string and now it works. – Marcos Junior Mar 12 '20 at 18:32

1 Answers1

0

Suppose it's caused by Path.GetFileName, I'm not testing with this method, I just test with the guid and it could work for me. The below is my test code, maybe you could change the GetBlockBlobReference.

       string storageConnectionString = "connection string";

        CloudStorageAccount storageAccount;

        CloudStorageAccount.TryParse(storageConnectionString, out storageAccount);

        CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();

        CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("test");
        string sourceFile = "C:\\Users\\georgec\\Downloads\\fileshare\\1.txt";

        String Path = "image/";
        var directory = cloudBlobContainer.GetDirectoryReference(Path);

        CloudBlockBlob cloudBlockBlob = directory.GetBlockBlobReference($"{Guid.NewGuid().ToString()}.txt");


        await cloudBlockBlob.UploadFromFileAsync(sourceFile);

enter image description here

George Chen
  • 13,703
  • 2
  • 11
  • 26