Пример #1
0
        private async Task <IActionResult> DownloadDirectoryFromS3Async(AmazonS3Client client, string downloadLocation)
        {
            string zipFolder = downloadLocation + ".zip";

            if (!Directory.Exists(downloadLocation))
            {
                Directory.CreateDirectory(downloadLocation);
            }

            var transferUtility = new TransferUtility(client);
            await transferUtility.DownloadDirectoryAsync(_bucketName, "\\", downloadLocation);

            return(CreateZip(downloadLocation, zipFolder));
        }
Пример #2
0
        // S3 download
        private static async Task DownloadDirAsync(IAmazonS3 s3Client, string bucketName, string s3Directory, string localDirectory)
        {
            try
            {
                // create the directoryTransferUtility object
                var directoryTransferUtility = new TransferUtility(s3Client);

                // download a s3 directory
                await directoryTransferUtility.DownloadDirectoryAsync(bucketName, s3Directory, localDirectory);
            }
            catch (AmazonS3Exception e)
            {
                Console.WriteLine("Error encountered ***. Message:'{0}' when writing an object", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
            }
        }
Пример #3
0
        public async Task <AnnotationPackage> DownloadPackageAsync(AnnotationPackage package, CancellationToken token = default(CancellationToken))
        {
            this._packagesToDownload.Enqueue(package);

            package.Enqueued = true;

            while (this._packagesToDownload.Peek() != package)
            {
                await Task.Delay(1000).ConfigureAwait(false);
            }

            package.Enqueued = false;

            this._downloadedPackage = package;

            if (!Directory.Exists(this._extractionFolder))
            {
                Directory.CreateDirectory(this._extractionFolder);
            }

            var packagePath = Path.Combine(this._extractionFolder, package.PackageName);
            var tempPath    = $"{packagePath}_temp";

            if (Directory.Exists(packagePath))
            {
                Directory.Delete(packagePath, true);
            }

            var files = await this._s3Client.ListObjectsV2Async(new ListObjectsV2Request
            {
                BucketName = this._bucketName,
                Prefix     = package.PackageName
            });

            var request = new TransferUtilityDownloadDirectoryRequest
            {
                BucketName     = this._bucketName,
                S3Directory    = package.PackageName,
                LocalDirectory = tempPath
            };

            request.DownloadedDirectoryProgressEvent += this.DownloadedDirectoryProgressEvent;

            try
            {
                using (var fileTransferUtility = new TransferUtility(this._s3Client))
                {
                    await fileTransferUtility.DownloadDirectoryAsync(request, token).ConfigureAwait(false);
                }
            }
            finally
            {
                request.DownloadedDirectoryProgressEvent -= this.DownloadedDirectoryProgressEvent;
                package.Downloading = false;
            }

            if (Directory.Exists(tempPath))
            {
                Directory.Move(tempPath, packagePath);
            }

            package.AvailableLocally = true;

            var path = Path.Combine(this._extractionFolder, package.PackageName);

            package.PrepareImages(path);

            this._packagesToDownload.Dequeue();

            return(package);
        }
Пример #4
0
 public async Task Copy(string fromDir, string toDir)
 {
     var fileTransferUtility = new TransferUtility(s3Client);
     await fileTransferUtility.DownloadDirectoryAsync(config.S3.Bucket, fromDir, toDir);
 }