44
55namespace NpgsqlRest . UploadHandlers . Handlers ;
66
7- public class FileSystemUploadHandler ( NpgsqlRestUploadOptions options , ILogger ? logger ) : UploadHandler , IUploadHandler
7+ public class FileSystemUploadHandler ( NpgsqlRestUploadOptions options , ILogger ? logger ) : BaseUploadHandler , IUploadHandler
88{
99 private string [ ] ? _uploadedFiles = null ;
1010
@@ -16,7 +16,7 @@ protected override IEnumerable<string> GetParameters()
1616 {
1717 yield return IncludedMimeTypeParam ;
1818 yield return ExcludedMimeTypeParam ;
19- yield return BufferSize ;
19+ yield return BufferSizeParam ;
2020 yield return PathParam ;
2121 yield return FileParam ;
2222 yield return UniqueNameParam ;
@@ -31,14 +31,12 @@ protected override IEnumerable<string> GetParameters()
3131
3232 public async Task < string > UploadAsync ( NpgsqlConnection connection , HttpContext context , Dictionary < string , string > ? parameters )
3333 {
34- var ( includedMimeTypePatterns , excludedMimeTypePatterns , bufferSize ) = ParseSharedParameters ( options , parameters ) ;
35-
36- var basePath = options . DefaultUploadHandlerOptions . FileSystemHandlerPath ;
37- var useUniqueFileName = options . DefaultUploadHandlerOptions . FileSystemHandlerUseUniqueFileName ;
34+ var basePath = options . DefaultUploadHandlerOptions . FileSystemPath ;
35+ var useUniqueFileName = options . DefaultUploadHandlerOptions . FileSystemUseUniqueFileName ;
3836 string ? newFileName = null ;
39- bool createPathIfNotExists = options . DefaultUploadHandlerOptions . FileSystemHandlerCreatePathIfNotExists ;
40- bool checkText = false ;
41- bool checkImage = false ;
37+ bool createPathIfNotExists = options . DefaultUploadHandlerOptions . FileSystemCreatePathIfNotExists ;
38+ bool checkText = options . DefaultUploadHandlerOptions . FileSystemCheckText ;
39+ bool checkImage = options . DefaultUploadHandlerOptions . FileSystemCheckImage ;
4240 int testBufferSize = options . DefaultUploadHandlerOptions . TextTestBufferSize ;
4341 int nonPrintableThreshold = options . DefaultUploadHandlerOptions . TextNonPrintableThreshold ;
4442
@@ -93,10 +91,8 @@ public async Task<string> UploadAsync(NpgsqlConnection connection, HttpContext c
9391
9492 if ( options . LogUploadParameters is true )
9593 {
96- #pragma warning disable CA2253 // Named placeholders should not be numeric values
97- logger ? . LogInformation ( "Upload for {0}: includedMimeTypePatterns={1}, excludedMimeTypePatterns={2}, bufferSize={3}, basePath={4}, useUniqueFileName={5}, newFileName={6}, createPathIfNotExists={7}, checkText={8}, checkImage={9}, allowedImage={10}, testBufferSize={11}, nonPrintableThreshold={12}" ,
98- _type , includedMimeTypePatterns , excludedMimeTypePatterns , bufferSize , basePath , useUniqueFileName , newFileName , createPathIfNotExists , checkText , checkImage , allowedImage , testBufferSize , nonPrintableThreshold ) ;
99- #pragma warning disable CA2253 // Named placeholders should not be numeric values
94+ logger ? . LogInformation ( "Upload for {_type}: includedMimeTypePatterns={includedMimeTypePatterns}, excludedMimeTypePatterns={excludedMimeTypePatterns}, bufferSize={bufferSize}, basePath={basePath}, useUniqueFileName={useUniqueFileName}, newFileName={newFileName}, createPathIfNotExists={createPathIfNotExists}, checkText={checkText}, checkImage={checkImage}, allowedImage={allowedImage}, testBufferSize={testBufferSize}, nonPrintableThreshold={nonPrintableThreshold}" ,
95+ _type , _includedMimeTypePatterns , _excludedMimeTypePatterns , _bufferSize , basePath , useUniqueFileName , newFileName , createPathIfNotExists , checkText , checkImage , allowedImage , testBufferSize , nonPrintableThreshold ) ;
10096 }
10197
10298 if ( createPathIfNotExists is true && Directory . Exists ( basePath ) is false )
@@ -147,7 +143,11 @@ public async Task<string> UploadAsync(NpgsqlConnection connection, HttpContext c
147143 result . Append ( SerializeString ( currentFilePath ) ) ;
148144
149145 UploadFileStatus status = UploadFileStatus . Ok ;
150- if ( formFile . ContentType . CheckMimeTypes ( includedMimeTypePatterns , excludedMimeTypePatterns ) is false )
146+ if ( _stopAfterFirstSuccess is true && _skipFileNames . Contains ( formFile . FileName , StringComparer . OrdinalIgnoreCase ) )
147+ {
148+ status = UploadFileStatus . Ignored ;
149+ }
150+ if ( status == UploadFileStatus . Ok && this . CheckMimeTypes ( formFile . ContentType ) is false )
151151 {
152152 status = UploadFileStatus . InvalidMimeType ;
153153 }
@@ -176,10 +176,14 @@ public async Task<string> UploadAsync(NpgsqlConnection connection, HttpContext c
176176 fileId ++ ;
177177 continue ;
178178 }
179+ if ( _stopAfterFirstSuccess is true )
180+ {
181+ _skipFileNames . Add ( formFile . FileName ) ;
182+ }
179183
180184 using ( var fileStream = new FileStream ( currentFilePath , FileMode . Create ) )
181185 {
182- byte [ ] buffer = new byte [ bufferSize ] ;
186+ byte [ ] buffer = new byte [ _bufferSize ] ;
183187 int bytesRead ;
184188 using var sourceStream = formFile . OpenReadStream ( ) ;
185189
0 commit comments