@@ -18,29 +18,32 @@ public class GCPStorage : IGCPStorage
1818{
1919 private readonly string _bucket ;
2020 private readonly StorageClient _storageClient ;
21+ private readonly GCPStorageOptions _gcpStorageOptions ;
2122
2223 public GCPStorage ( GCPStorageOptions gcpStorageOptions )
2324 {
24- _bucket = gcpStorageOptions . BucketOptions . Bucket ;
25+ _gcpStorageOptions = gcpStorageOptions ;
2526
26- if ( gcpStorageOptions . StorageClientBuilder != null )
27+ _bucket = _gcpStorageOptions . BucketOptions . Bucket ;
28+
29+ if ( _gcpStorageOptions . StorageClientBuilder != null )
2730 {
28- _storageClient = gcpStorageOptions . StorageClientBuilder . Build ( ) ;
31+ _storageClient = _gcpStorageOptions . StorageClientBuilder . Build ( ) ;
2932 }
30- else if ( gcpStorageOptions . GoogleCredential != null )
33+ else if ( _gcpStorageOptions . GoogleCredential != null )
3134 {
3235 _storageClient = StorageClient . Create ( gcpStorageOptions . GoogleCredential ) ;
3336 }
3437
3538 try
3639 {
37- if ( gcpStorageOptions . OriginalOptions != null )
40+ if ( _gcpStorageOptions . OriginalOptions != null )
3841 {
39- _storageClient . CreateBucket ( gcpStorageOptions . BucketOptions . ProjectId , _bucket , gcpStorageOptions . OriginalOptions ) ;
42+ _storageClient . CreateBucket ( _gcpStorageOptions . BucketOptions . ProjectId , _bucket , _gcpStorageOptions . OriginalOptions ) ;
4043 }
4144 else
4245 {
43- _storageClient . CreateBucket ( gcpStorageOptions . BucketOptions . ProjectId , _bucket ) ;
46+ _storageClient . CreateBucket ( _gcpStorageOptions . BucketOptions . ProjectId , _bucket ) ;
4447 }
4548 }
4649 catch
@@ -263,4 +266,24 @@ private async Task UploadStreamInternalAsync(string blobName, Stream dataStream,
263266 }
264267
265268 #endregion
269+
270+ #region CreateContainer
271+ public async Task CreateContainerAsync ( )
272+ {
273+ try
274+ {
275+ if ( _gcpStorageOptions . OriginalOptions != null )
276+ {
277+ await _storageClient . CreateBucketAsync ( _gcpStorageOptions . BucketOptions . ProjectId , _bucket , _gcpStorageOptions . OriginalOptions ) ;
278+ }
279+ else
280+ {
281+ await _storageClient . CreateBucketAsync ( _gcpStorageOptions . BucketOptions . ProjectId , _bucket ) ;
282+ }
283+ }
284+ catch
285+ {
286+ }
287+ }
288+ #endregion
266289}
0 commit comments