Пример #1
0
        private async Task <bool> ProcessZipFileItemsAsync(string bucketName, string key, Func <ZipArchiveEntry, Task> callbackAsync)
        {
            var tmpFilename = Path.GetTempFileName() + ".zip";

            try {
                _logger.LogInfo($"downloading s3://{bucketName}/{key}");
                await _transferUtility.DownloadAsync(new TransferUtilityDownloadRequest {
                    BucketName = bucketName,
                    Key        = key,
                    FilePath   = tmpFilename
                });
            } catch (Exception e) {
                _logger.LogErrorAsWarning(e, "s3 download failed");
                return(false);
            }
            try {
                using (var zip = ZipFile.Open(tmpFilename, ZipArchiveMode.Read)) {
                    foreach (var entry in zip.Entries)
                    {
                        await callbackAsync(entry);
                    }
                }
            } finally {
                try {
                    File.Delete(tmpFilename);
                } catch { }
            }
            return(true);
        }
Пример #2
0
 public async Task <Response <S3WriterResourceAttribute> > Delete(S3WriterResourceProperties properties)
 {
     _logger.LogInfo($"deleting JSON file at s3://{properties.BucketName}/{properties.Key}");
     try {
         await _s3Client.DeleteObjectAsync(new DeleteObjectRequest {
             BucketName = properties.BucketName,
             Key        = properties.Key
         });
     } catch (Exception e) {
         _logger.LogErrorAsWarning(e, "unable to delete JSON file at s3://{0}/{1}", properties.BucketName, properties.Key);
     }
     return(new Response <S3WriterResourceAttribute>());
 }