예제 #1
0
        public async Task <IFileInformation> StoreFile(Stream fileStream)
        {
            var uniqueName = Guid.NewGuid().ToString();
            // try
            // {
            //     uniqueName = uniqueName.ApplyExtension(name, contentType);
            // }
            // catch (Exception ex)
            // {
            //     _logger.LogWarning(ex.Message);
            // }

            var fileTransferUtility = new TransferUtility(S3Settings.AccessKeyId, S3Settings.SecretAccessKey, _region);

            var request = new TransferUtilityUploadRequest
            {
                ServerSideEncryptionMethod = ServerSideEncryptionMethod.AES256,
                BucketName  = S3Settings.Bucket,
                Key         = uniqueName,
                InputStream = fileStream,
                PartSize    = CHUNK_SIZE
            };

            await fileTransferUtility.UploadAsync(request);

            var info = new S3FileInformation {
                StorageIdentifier = uniqueName
            };

            return(info);
        }
예제 #2
0
        public async Task <IFileInformation> CopyFileToSameServiceType(string identifier, IStorageService destinationService)
        {
            var destination = (S3StorageService)destinationService;

            var uniqueName = Guid.NewGuid().ToString();

            using var client = new AmazonS3Client(S3Settings.AccessKeyId, S3Settings.SecretAccessKey, _region);
            var request = new CopyObjectRequest()
            {
                SourceBucket      = S3Settings.Bucket,
                SourceKey         = identifier,
                DestinationBucket = destination.S3Settings.Bucket,
                DestinationKey    = uniqueName
            };

            await client.CopyObjectAsync(request);

            var info = new S3FileInformation {
                StorageIdentifier = uniqueName
            };

            return(info);
        }