/// <summary>根据Bucket信息获取S3客户端 /// </summary> public IAmazonS3 GetClientByBucket(BucketInfo bucket) { var identifier = ConvertToIdentifier(bucket); if (_clientDict.TryGetValue(identifier, out IAmazonS3 client)) { return(client); } //不存在该类型的客户端,则新建 if (bucket.VendorName == S3Vendor.KS3Name) { var config = new AmazonKS3Config() { ServiceURL = bucket.ServerUrl, ForcePathStyle = bucket.ForcePathStyle, SignatureVersion = bucket.SignatureVersion, }; client = new AmazonKS3Client(bucket.AccessKeyId, bucket.SecretAccessKey, config); } else { var config = new AmazonS3Config() { ServiceURL = bucket.ServerUrl, ForcePathStyle = bucket.ForcePathStyle, SignatureVersion = bucket.SignatureVersion, }; client = new AmazonS3Client(bucket.AccessKeyId, bucket.SecretAccessKey, config); } //添加到集合中 _clientDict.AddOrUpdate(identifier, client, (i, c) => { return(client); }); return(client); }
/// <summary>是否分片上传 /// </summary> private bool IsMultipartUpload(BucketInfo bucket, UploadFileInfo info) { var size = GetFileSize(info); //如果有文件流,则从流中获取数据大小 return(size > bucket.SliceSize); }
/// <summary>根据Bucket信息转换成客户端标志 /// </summary> private S3ClientIdentifier ConvertToIdentifier(BucketInfo bucket) { return(new S3ClientIdentifier(bucket.AccessKeyId, bucket.SecretAccessKey, new S3Vendor(bucket.VendorName, bucket.VendorVersion))); //return new S3ClientIdentifier(bucket.AccessKeyId, bucket.SecretAccessKey, bucket.Vendor); }