示例#1
0
 // really dont like the idea of storing plain passwords.
 // need to encrypt the app.config soon.
 public DropboxHandler(string url)
 {
     if (!string.IsNullOrWhiteSpace(url))
     {
         // Create default client. Can override later if required.
         client            = DropboxHelper.GetClient();
         baseUrl           = url;
         defaultBlobPrefix = GetBlobPrefixFromUrl(url);
     }
 }
示例#2
0
        /// <summary>
        /// Makes a usable URL for a blob. This will need to handle security on the source blob.
        /// Each cloud provider is different.
        /// Cloud providers developed:
        ///     Azure
        ///     S3xx
        ///
        /// Cloud providers soon:
        ///     Dropbox
        ///     Onedrive
        /// </summary>
        /// <param name="origBlob"></param>
        /// <returns></returns>
        private static string GeneratedAccessibleUrl(BasicBlobContainer origBlob)
        {
            var    sourceUrl = origBlob.Url; // +"/" + origBlob.Name;
            string url       = "";

            // if S3, then generate signed url.
            if (S3Helper.MatchHandler(sourceUrl))
            {
                var bucket = S3Helper.GetBucketFromUrl(sourceUrl);
                var key    = origBlob.Name;
                url = S3Helper.GeneratePreSignedUrl(bucket, key);
            }
            else if (AzureHelper.MatchHandler(sourceUrl))
            {
                // generate Azure signed url.
                var client = AzureHelper.GetSourceCloudBlobClient(sourceUrl);
                var policy = new SharedAccessBlobPolicy();
                policy.SharedAccessStartTime  = DateTime.UtcNow.AddMinutes(-1);
                policy.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(ConfigHelper.SharedAccessSignatureDurationInSeconds / 60);
                policy.Permissions            = SharedAccessBlobPermissions.Read;
                var blob = client.GetBlobReferenceFromServer(new Uri(sourceUrl));
                url = sourceUrl + blob.GetSharedAccessSignature(policy);
            }
            else if (DropboxHelper.MatchHandler(sourceUrl))
            {
                // need shorter url. (no base url);
                var uri      = new Uri(sourceUrl);
                var shortUrl = uri.PathAndQuery;
                var client   = DropboxHelper.GetClient();
                var media    = client.GetMedia(shortUrl);
                return(media.Url);
            }
            else if (SkyDriveHelper.MatchHandler(sourceUrl))
            {
                throw new NotImplementedException("Blobcopy against onedrive is not implemented yet");
            }

            Console.WriteLine("shared url is {0}", url);
            return(url);
        }