Azure WCF service gives error on blob storage file

Beantwortet Azure WCF service gives error on blob storage file

  • Freitag, 4. Mai 2012 11:16
     
      Enthält Code

    I have an Windows Azure project with a WCF service as WebRole.
    I have a storage account in Azure where I want to save a file on.

    My code worked as I tested with the Azure emulator.

    But know I got next error:

        Could not find a part of the path 'C:\temp\BatchAzure.log'.

    Clientside the service I'm trying to execute:

            string path = @"C:\temp\BatchAzure.log";
            var test = service.SaveGezichtBestand(path, "999999");

    The method I'm using:

        public bool SaveGezichtBestand(string filePath, string memberID)
                {
                    bool result = false;
        
                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
                    RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
        
                    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        
                    // Retrieve a reference to a container 
                    CloudBlobContainer container = blobClient.GetContainerReference("facefileblobcontainer");
        
                    // Create the container if it doesn't already exist
                    container.CreateIfNotExist();
        
                    //By default, the new container is private, so you must specify your storage account key (as you did above) 
                    //to download blobs from this container.
                    container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
        
                    // Retrieve reference to a blob named "myblob"
                    CloudBlob blob = container.GetBlobReference(memberID);
        
                    try
                    {
                        // Create or overwrite the "myblob" blob with contents from a local file
                        using (var fileStream = System.IO.File.OpenRead(filePath))
                        {
                            blob.UploadFromStream(fileStream);
                            result = true;
                        }
                    }
                    catch (Exception)
                    {
                        result = false;
                        throw;
                    }
        
                    return result;
                }
    • Verschoben Herve RoggeroMVP Freitag, 4. Mai 2012 12:31 This is an Azure Storage thread (From:SQL Azure)
    •  

Alle Antworten

  • Freitag, 4. Mai 2012 13:16
    Moderator
     
     Beantwortet
    I'm guessing that the problem isn't with Windows Azure Storage but with how you are creating the file (aka your filePath variable). Its indicating that the file doesn't exist. How many instances of the service are you running and does this method execute as part of the same request that created the file? If you're running multiple instances and this method is called on a second service call, its highly likely you that you got bit by assuming Windows Azure supported sticky sessions. In this scenario the file was likely created on one role instance and the request to return the file was being served by a second role instance. Each instance has its own 'C:\temp' directory.
  • Freitag, 4. Mai 2012 16:28
     
     

    Hi, aint possible cause I'm using 1 instance.

    But thanks for the info!

  • Montag, 7. Mai 2012 02:13
    Moderator
     
     Beantwortet

    Hi,

    Agree. It looks like your azure application could not find the file with "C:\temp\BatchAzure.log" and i am not sure your applicatin has privilege to create and access file under tha temp folder.

    The recommended way is localStorage, you can maintain and manage files in localStorage and decide upload or do other thing with them.

    A simple tutorial about LocalStorage in Azure:

    http://vkreynin.wordpress.com/2010/01/10/learning-azure-local-storage-with-me/

    Hope this helps.


    Please mark the replies as answers if they help or unmark if not. If you have any feedback about my replies, please contact msdnmg@microsoft.com Microsoft One Code Framework