@@ -51,6 +51,8 @@ public class ExternalProviderS3 : ExternalProviderBase, ExternalProvider
5151 bool customEndpoint = false ;
5252
5353 bool objectOwnershipEnabled ;
54+ private enum BucketPrivacy { PRIVATE , PUBLIC } ;
55+ private BucketPrivacy ownerEnforcedBucketPrivacy ;
5456
5557 public string StorageUri
5658 {
@@ -106,7 +108,11 @@ private void Initialize() {
106108 }
107109 }
108110
109- objectOwnershipEnabled = ! GetPropertyValue ( DEFAULT_ACL , DEFAULT_ACL_DEPRECATED , "" ) . Equals ( "Bucket owner enforced" ) ;
111+ string default_storage_privacy = GetPropertyValue ( DEFAULT_ACL , DEFAULT_STORAGE_PRIVACY , "" ) ;
112+ objectOwnershipEnabled = ! default_storage_privacy . Contains ( "Bucket owner enforced" ) ;
113+ ownerEnforcedBucketPrivacy = ( BucketPrivacy ) ( ! objectOwnershipEnabled ?
114+ ( default_storage_privacy . Contains ( "private" ) ? BucketPrivacy . PRIVATE : BucketPrivacy . PUBLIC )
115+ : ( BucketPrivacy ? ) null ) ;
110116
111117#if NETCORE
112118 if ( credentials != null )
@@ -243,7 +249,10 @@ public string Upload(string localFile, string objectName, GxFileType fileType)
243249
244250 private bool IsPrivateUpload ( GxFileType fileType )
245251 {
246- return ( GetCannedACL ( fileType ) != S3CannedACL . PublicRead ) && objectOwnershipEnabled ;
252+ if ( objectOwnershipEnabled && GetCannedACL ( fileType ) != S3CannedACL . PublicRead )
253+ return true ;
254+ else
255+ return ownerEnforcedBucketPrivacy == BucketPrivacy . PRIVATE ;
247256 }
248257
249258 public string Get ( string objectName , GxFileType fileType , int urlMinutes = 0 )
@@ -264,7 +273,7 @@ public string GetUrl(string objectName, GxFileType fileType, int urlMinutes = 0)
264273 private string GetUrlImpl ( string objectName , GxFileType fileType , int urlMinutes = 0 )
265274 {
266275 bool isPrivate = IsPrivateUpload ( fileType ) ;
267- return ( isPrivate ) ? GetPreSignedUrl ( objectName , ResolveExpiration ( urlMinutes ) . TotalMinutes ) : StorageUri + StorageUtils . EncodeUrlPath ( objectName ) ;
276+ return ( isPrivate ) ? GetPreSignedUrl ( objectName , ResolveExpiration ( urlMinutes ) . TotalMinutes ) : IsPrivateUpload ( fileType ) ? GetPreSignedUrl ( objectName , ResolveExpiration ( urlMinutes ) . TotalMinutes ) : StorageUri + StorageUtils . EncodeUrlPath ( objectName ) ;
268277
269278 }
270279
@@ -323,7 +332,9 @@ public string Rename(string objectName, string newName, GxFileType fileType)
323332 {
324333 Copy ( objectName , fileType , newName , fileType ) ;
325334 Delete ( objectName , fileType ) ;
326- return StorageUri + StorageUtils . EncodeUrlPath ( newName ) ;
335+ if ( objectOwnershipEnabled )
336+ return StorageUri + StorageUtils . EncodeUrlPath ( newName ) ;
337+ return IsPrivateUpload ( fileType ) ? GetPreSignedUrl ( objectName , defaultExpiration . Minutes ) : StorageUri + StorageUtils . EncodeUrlPath ( newName ) ;
327338 }
328339
329340 public string Copy ( string objectName , GxFileType sourceFileType , string newName , GxFileType destFileType )
@@ -348,7 +359,9 @@ public string Copy(string objectName, GxFileType sourceFileType, string newName,
348359 }
349360
350361 CopyObject ( request ) ;
351- return StorageUri + StorageUtils . EncodeUrlPath ( newName ) ;
362+ if ( objectOwnershipEnabled )
363+ return StorageUri + StorageUtils . EncodeUrlPath ( newName ) ;
364+ return IsPrivateUpload ( sourceFileType ) ? GetPreSignedUrl ( objectName , defaultExpiration . Minutes ) : StorageUri + StorageUtils . EncodeUrlPath ( newName ) ;
352365 }
353366
354367 private S3CannedACL GetCannedACL ( GxFileType acl )
@@ -466,7 +479,9 @@ public string Copy(string url, string newName, string tableName, string fieldNam
466479 AddObjectMetadata ( request . Metadata , tableName , fieldName , resourceKey ) ;
467480 CopyObject ( request ) ;
468481
469- return StorageUri + StorageUtils . EncodeUrlPath ( resourceKey ) ;
482+ if ( objectOwnershipEnabled )
483+ return StorageUri + StorageUtils . EncodeUrlPath ( resourceKey ) ;
484+ return IsPrivateUpload ( destFileType ) ? GetPreSignedUrl ( resourceKey , defaultExpiration . Minutes ) : StorageUri + StorageUtils . EncodeUrlPath ( resourceKey ) ;
470485 }
471486
472487 public string Save ( Stream fileStream , string fileName , string tableName , string fieldName , GxFileType destFileType )
@@ -493,7 +508,9 @@ public string Save(Stream fileStream, string fileName, string tableName, string
493508 AddObjectMetadata ( objectRequest . Metadata , tableName , fieldName , resourceKey ) ;
494509 PutObjectResponse result = PutObject ( objectRequest ) ;
495510
496- return StorageUri + resourceKey ;
511+ if ( objectOwnershipEnabled )
512+ return StorageUri + resourceKey ;
513+ return IsPrivateUpload ( destFileType ) ? GetPreSignedUrl ( resourceKey , defaultExpiration . Minutes ) : StorageUri + StorageUtils . EncodeUrlPath ( resourceKey ) ;
497514 }
498515 catch ( Exception ex )
499516 {
0 commit comments