Beispiel #1
0
        public void UploadObject(UploadRequest request)
        {
            CheckUri(request.Uri);

            try
            {
                var client = cloudStorageAccount.CreateCloudBlobClient();
                client.ParallelOperationThreadCount = 1;

                var securityEnabled      = accessControlEnabledGlobally && !request.IgnoreAccessControl;
                var currentContainerName = securityEnabled ? securedContainerName : containerName;

                // Create container with specified security level
                var container = client.GetContainerReference(currentContainerName);
                if (request.CreateDirectory)
                {
                    if (container.CreateIfNotExists())
                    {
                        var permissions = new BlobContainerPermissions();
                        if (securityEnabled)
                        {
                            permissions.PublicAccess = BlobContainerPublicAccessType.Off;
                        }
                        else
                        {
                            permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
                        }
                        container.SetPermissions(permissions);
                    }
                }

                var blob = container.GetBlockBlobReference(request.Uri.AbsoluteUri);

                blob.Properties.ContentType  = MimeTypeUtility.DetermineContentType(request.Uri);
                blob.Properties.CacheControl = CacheControl;

                if (request.InputStream.Position != 0)
                {
                    request.InputStream.Position = 0;
                }

                blob.UploadFromStream(request.InputStream, options: new BlobRequestOptions {
                    MaximumExecutionTime = timeout, ServerTimeout = timeout
                });
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to upload object with request {0}.", request), e);
            }
        }
        public void UploadObject(UploadRequest request)
        {
            CheckUri(request.Uri);

            try
            {
                var client = cloudStorageAccount.CreateCloudBlobClient();
                client.ParallelOperationThreadCount = 1;

                var container = client.GetContainerReference(containerName);
                if (request.CreateDirectory)
                {
                    container.CreateIfNotExists();
                }

                var permissions = new BlobContainerPermissions();
                if (accessControlEnabledGlobally && !request.IgnoreAccessControl)
                {
                    permissions.PublicAccess = BlobContainerPublicAccessType.Off;
                }
                else
                {
                    permissions.PublicAccess = BlobContainerPublicAccessType.Blob;
                }
                container.SetPermissions(permissions);

                var blob = container.GetBlockBlobReference(request.Uri.AbsoluteUri);

                blob.Properties.ContentType  = MimeTypeUtility.DetermineContentType(request.Uri);
                blob.Properties.CacheControl = CacheControl;

                if (request.InputStream.Position != 0)
                {
                    request.InputStream.Position = 0;
                }

                blob.UploadFromStream(request.InputStream);
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to upload object with request {0}.", request), e);
            }
        }