@@ -146,16 +146,31 @@ public async Task UploadStreamAsync(string objectName, Stream fileStream, string
146146 }
147147 public Task < string > GetPublicFileUrlAsync ( string objectName )
148148 {
149- if ( string . IsNullOrWhiteSpace ( objectName ) || objectName . Any ( c => "!@#$%^&*()" . Contains ( c ) ) )
150- {
149+ if ( string . IsNullOrWhiteSpace ( objectName ) )
151150 throw new ArgumentException ( "Invalid object name" , nameof ( objectName ) ) ;
152- }
153151
154- var endpoint = ! string . IsNullOrWhiteSpace ( _config . PublicEndpoint ) ? _config . PublicEndpoint : _config . Endpoint ; // Ưu tiên PublicEndpoint
152+ var key = Uri . EscapeDataString ( objectName ) ;
153+
154+ // Nếu có PublicEndpoint thì dùng nó làm base (có thể gồm scheme + path), KHÔNG thêm :port
155+ var pub = _config . PublicEndpoint ? . Trim ( ) . TrimEnd ( '/' ) ;
156+ if ( ! string . IsNullOrEmpty ( pub ) )
157+ {
158+ // Nếu thiếu scheme thì tự thêm theo cấu hình Secure
159+ if ( ! pub . StartsWith ( "http://" , StringComparison . OrdinalIgnoreCase ) &&
160+ ! pub . StartsWith ( "https://" , StringComparison . OrdinalIgnoreCase ) )
161+ {
162+ pub = $ "{ ( _config . Secure ? "https" : "http" ) } ://{ pub } ";
163+ }
164+ var url = $ "{ pub } /{ _config . BucketName } /{ key } ";
165+ Console . WriteLine ( $ "Generated public URL: { url } ") ;
166+ return Task . FromResult ( url ) ;
167+ }
155168
156- var url = $ "{ ( _config . Secure ? "https" : "http" ) } ://{ endpoint } :{ _config . Port } /{ _config . BucketName } /{ objectName } ";
157- Console . WriteLine ( $ "Generated URL: { url } ") ;
158- return Task . FromResult ( url ) ;
169+ // Fallback: dùng endpoint nội bộ (có :port)
170+ var scheme = _config . Secure ? "https" : "http" ;
171+ var direct = $ "{ scheme } ://{ _config . Endpoint } :{ _config . Port } /{ _config . BucketName } /{ key } ";
172+ Console . WriteLine ( $ "Generated direct URL: { direct } ") ;
173+ return Task . FromResult ( direct ) ;
159174 }
160175
161176 public async Task < string > GeneratePresignedUrlAsync ( string objectName , int expirySeconds )
0 commit comments