public void UploadObject(UploadRequest request)
        {
            CheckUri(request.Uri);

            try
            {
                var absolutePath = ResolvePath(request.Uri.AbsoluteUri);

                if (request.CreateDirectory)
                {
                    var ftpDiretoryUri = ExtractPath(absolutePath);
                    TryCreateDirectory(ftpDiretoryUri);
                }

                request.InputStream.Position = 0;

                var serverUri  = string.Format("{0}{1}", ftpRoot, absolutePath);
                var ftpRequest = CreateFtpRequest(serverUri);
                ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;

                using (var requestSream = ftpRequest.GetRequestStream())
                {
                    Pump(request.InputStream, requestSream);
                }

                var ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                ftpResponse.Close();
            }
            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 absolutePath = ResolvePath(request.Uri.AbsoluteUri);

                if (request.CreateDirectory)
                {
                    var ftpDiretoryUri = ExtractPath(absolutePath);
                    TryCreateDirectory(ftpDiretoryUri, true);
                }

                request.InputStream.Position = 0;

                var serverUri = string.Format("{0}{1}", ftpRoot, absolutePath);
                var ftpRequest = CreateFtpRequest(serverUri);
                ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;

                using (var requestSream = ftpRequest.GetRequestStream())
                {
                    Pump(request.InputStream, requestSream);
                }

                var ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                ftpResponse.Close();
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to upload object with request {0}.", request), e);
            }
        }
        /// <summary>
        /// Creates the upload request.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <param name="useSmallImage">if set to <c>true</c> [use small image].</param>
        /// <returns></returns>
        protected UploadRequest CreateUploadRequest(ICmsConfiguration configuration, bool useSmallImage = true)
        {
            string url = Path.Combine(configuration.Storage.ContentRoot, useSmallImage ? TestImageFileName : TestBigImageFileName);
            var fileUri = new Uri(url);
            var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(useSmallImage ? TestImagePath : TestBigImagePath);

            var request = new UploadRequest
            {
                InputStream = stream,
                Uri = fileUri
            };

            return request;
        }
        public void UploadObject(UploadRequest request)
        {
            CheckUri(request.Uri);

            string pathRoot = Path.GetDirectoryName(request.Uri.LocalPath);
            if (pathRoot != null && !Directory.Exists(pathRoot))
            {
                Directory.CreateDirectory(pathRoot);
            }

            using (FileStream writeStream = new FileStream(request.Uri.LocalPath, FileMode.Create, FileAccess.Write))
            {
                request.InputStream.Seek(0, SeekOrigin.Begin);
                request.InputStream.CopyTo(writeStream);
                writeStream.Flush(true);
                writeStream.Close();
            }
        }
        public void UploadObject(UploadRequest request)
        {
            CheckUri(request.Uri);

            string pathRoot = Path.GetDirectoryName(request.Uri.LocalPath);

            if (pathRoot != null && !Directory.Exists(pathRoot))
            {
                Directory.CreateDirectory(pathRoot);
            }

            using (FileStream writeStream = new FileStream(request.Uri.LocalPath, FileMode.Create, FileAccess.Write))
            {
                request.InputStream.Seek(0, SeekOrigin.Begin);
                request.InputStream.CopyTo(writeStream);
                writeStream.Flush(true);
                writeStream.Close();
            }
        }
Beispiel #6
0
        public void CopyObject(Uri sourceUri, Uri destinationUri)
        {
            CheckUri(sourceUri);
            CheckUri(destinationUri);

            try
            {
                var response = DownloadObject(sourceUri);

                UploadRequest request = new UploadRequest();
                request.Uri = destinationUri;
                request.InputStream = new MemoryStream();

                response.ResponseStream.Position = 0;
                response.ResponseStream.CopyTo(request.InputStream);

                UploadObject(request);
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to copy object. SourceUrl: {0}, DestinationUrl: {1}", sourceUri, destinationUri), e);
            }
        }
        public void CopyObject(Uri sourceUri, Uri destinationUri)
        {
            CheckUri(sourceUri);
            CheckUri(destinationUri);

            try
            {
                var response = DownloadObject(sourceUri);

                UploadRequest request = new UploadRequest();
                request.Uri         = destinationUri;
                request.InputStream = new MemoryStream();

                response.ResponseStream.Position = 0;
                response.ResponseStream.CopyTo(request.InputStream);

                UploadObject(request);
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to copy object. SourceUrl: {0}, DestinationUrl: {1}", sourceUri, destinationUri), e);
            }
        }
        public void UploadObject(UploadRequest request)
        {
            CheckUri(request.Uri);

            try
            {
                var putRequest = new PutObjectRequest();
                using (var client = CreateAmazonS3Client())
                {
                    var absolutePath = HttpUtility.UrlDecode(request.Uri.AbsolutePath);
                    var key = absolutePath.TrimStart(Convert.ToChar("/"));

                    putRequest.WithBucketName(bucketName)
                        .WithKey(key)
                        .WithInputStream(request.InputStream);

                    if (accessControlEnabledGlobally && !request.IgnoreAccessControl)
                    {
                        putRequest.WithCannedACL(S3CannedACL.Private);
                    }
                    else
                    {
                        putRequest.WithCannedACL(S3CannedACL.PublicRead);
                    }

                    if (request.Headers != null && request.Headers.Count > 0)
                    {
                        putRequest.AddHeaders(request.Headers);
                    }

                    if (request.MetaData != null && request.MetaData.Count > 0)
                    {
                        putRequest.WithMetaData(request.MetaData);
                    }

                    putRequest.ContentType = MimeTypeUtility.DetermineContentType(request.Uri);

                    using (client.PutObject(putRequest))
                    {
                    }
                }
            }
            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);
            }
        }
        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);
            }
        }
        private void GetUploadRequest(Uri uri, IStorageService azure)
        {
            var request = new UploadRequest();

            using (var file = File.OpenRead(@"C:\Users\Vytautas\Pictures\Koala.jpg"))
            {
                request.InputStream = file;
                request.Uri = uri;
                request.CreateDirectory = true;
                azure.UploadObject(request);
            }
        }
        public void UploadObject(UploadRequest request)
        {
            CheckUri(request.Uri);

            try
            {
                var putRequest = new PutObjectRequest();
                using (var client = CreateAmazonS3Client())
                {
                    var absolutePath = request.Uri.AbsolutePath;
                    var key = absolutePath.TrimStart(Convert.ToChar("/"));

                    putRequest.WithBucketName(bucketName)
                        .WithKey(key)
                        .WithCannedACL(S3CannedACL.PublicRead)
                        .WithInputStream(request.InputStream);

                    if (request.Headers != null && request.Headers.Count > 0)
                    {
                        putRequest.AddHeaders(request.Headers);
                    }

                    if (request.MetaData != null && request.MetaData.Count > 0)
                    {
                        putRequest.WithMetaData(request.MetaData);
                    }

                    using (client.PutObject(putRequest))
                    {
                    }
                }
            }
            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 blob = container.GetBlockBlobReference(request.Uri.AbsoluteUri);

                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);
            }
        }