@@ -7777,6 +7777,10 @@ $this.'.Topics'
7777
7777
<Type >
7778
7778
<Name >System.Net.HttpListenerRequest</Name >
7779
7779
<Members >
7780
+ <AliasProperty >
7781
+ <Name >Files</Name >
7782
+ <ReferencedMemberName >File</ReferencedMemberName >
7783
+ </AliasProperty >
7780
7784
<AliasProperty >
7781
7785
<Name >Form</Name >
7782
7786
<ReferencedMemberName >FormData</ReferencedMemberName >
@@ -7881,6 +7885,63 @@ if ($this.ContentType -match 'multipart.+?;') {
7881
7885
7882
7886
</GetScriptBlock >
7883
7887
</ScriptProperty >
7888
+ <ScriptProperty >
7889
+ <Name >File</Name >
7890
+ <GetScriptBlock >
7891
+ $boundary = $this.Boundary
7892
+ if (-not $boundary) { return }
7893
+ if ($this.'.CachedFiles') {
7894
+ return $this.'.CachedFiles'
7895
+ }
7896
+ if (-not $this.'.CachedRequestBody') {
7897
+ $body = $this.Body
7898
+ $rawData = $this.'.CachedRequestBody'
7899
+ }
7900
+ if (-not $rawData) { return}
7901
+
7902
+ $uploadedFiles = [Ordered]@{}
7903
+
7904
+ $boundaries = [Regex]::Matches($rawData, $boundary)
7905
+ for ($i = 0; $i -lt ($boundaries.Count - 1); $i++) {
7906
+ $startBoundary, $endBoundary = $boundaries[$i], $boundaries[$i + 1]
7907
+ $realStart = $startBoundary.Index + $startBoundary.Length
7908
+ $realEnd= $endBoundary.Index - 2
7909
+ $boundryContent = $rawData.Substring($realStart, $realEnd - $realStart)
7910
+ $s = $boundryContent.IndexOf("`r`n`r`n")
7911
+ if ($s -ne -1) {
7912
+ $preamble = $boundryContent.Substring(0, $s)
7913
+ $s+=4
7914
+ $name =
7915
+ foreach ($_ in $preamble -split ';') {
7916
+ $_ = $_.Trim()
7917
+ if ($_.StartsWith('name=')) {
7918
+ $_.Substring(5).Trim('"').Trim("'")
7919
+ break
7920
+ }
7921
+ }
7922
+
7923
+ $null= $ms.Seek($realStart + $s, 0)
7924
+ $buffer = [byte[]]::new($realEnd - ($realStart + $s))
7925
+ $bytesRead = $ms.Read($buffer,0, $buffer.Length)
7926
+ if ($preamble.IndexOf('Content-Type', [StringComparison]::OrdinalIgnoreCase) -eq -1) {
7927
+ $ms2 = [io.memorystream]::new($buffer)
7928
+ $sr2 = [io.StreamReader]::new($ms2, $this.ContentEncoding)
7929
+ $uploadedFiles[$name] = $sr2.ReadToEnd().TrimEnd()
7930
+ $sr2.Dispose()
7931
+ $ms2.Dispose()
7932
+ } else {
7933
+ $uploadedFiles[$name] = $buffer
7934
+ }
7935
+ }
7936
+ }
7937
+
7938
+ $this.psobject.properties.add((
7939
+ [psnoteproperty]::new('.CachedFiles', $uploadedFiles)
7940
+ ))
7941
+
7942
+ return $uploadedFiles
7943
+ </GetScriptBlock >
7944
+ </ScriptProperty >
7884
7945
<ScriptProperty >
7885
7946
<Name >FormData</Name >
7886
7947
<GetScriptBlock >
0 commit comments