Download file from the cloud storage

Availability: SharpBox 1.0

The following example shows how to download a file from the root of an existing cloud storage. This example uses the implemented drop box storage provider, so it needs also a valid dropbox configuration. To get the sample up and running an own dropbox account is neccessary. Additionally a valid application key and secret is needed. If you don't have one, use our test-application.
            // instanciate a new credentials object, e.g. for dropbox
            DropBox.DropBoxCredentials credentials = new AppLimit.CloudComputing.SharpBox.DropBox.DropBoxCredentials();

            // attach the application information 
            credentials.ConsumerKey = "TheApplicationKey";
            credentials.ComsumerSecret = "TheApplicationSecret";

            // add the account information
            credentials.UserName = "myaccount@dropbox.com";
            credentials.Password = "mypassword";

            // instanciate a cloud storage configuration, e.g. for dropbox
            DropBox.DropBoxConfiguration configuration = DropBox.DropBoxConfiguration.GetStandardConfiguration();

            // instanciate the cloudstorage manager
            CloudStorage storage = new CloudStorage();

            // open the connection to the storage
            storage.Open(configuration, credentials);            

            // get the root entry of the cloud storage 
            ICloudDirectoryEntry root = storage.GetRoot();
            if (root == null)
            {
                Console.WriteLine("No root object found");
            }
            else
            {
                // get the file entry
                ICloudFileSystemEntry file = root.GetChild("xxx.txt");

                // build a caching stream
                MemoryStream stream = new MemoryStream();

                // download the data
                file.GetDataTransferAccessor().Transfer(stream, nTransferDirection.nDownload, null, null);
                
                // go to start
                stream.Position = 0;

                // build a stream read
                StreamReader reader = new StreamReader(stream);
                Console.WriteLine("Info: {0}", reader.ReadToEnd());                

                // close the streamreader and the stream
                reader.Close();     
            }

            // close the cloud storage connection
            if (storage.IsOpened)
            {
                storage.Close();
            }
        

Last edited Aug 6, 2011 at 5:37 AM by dei79, version 4

Comments

No comments yet.