From d35e5482345f7e570c8060323176551c623b986d Mon Sep 17 00:00:00 2001
From: acommonusername <130874097+acommonusername@users.noreply.github.com>
Date: Sun, 30 Apr 2023 23:37:31 +0200
Subject: [PATCH 1/5] Update Responses.ps1

---
 src/Public/Responses.ps1 | 46 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 43 insertions(+), 3 deletions(-)

diff --git a/src/Public/Responses.ps1 b/src/Public/Responses.ps1
index 8f55dad3a..5adc560fe 100644
--- a/src/Public/Responses.ps1
+++ b/src/Public/Responses.ps1
@@ -1230,7 +1230,15 @@ function Save-PodeRequestFile
 
         [Parameter()]
         [string[]]
-        $FileName
+        $FileName,
+		
+		[Parameter()]
+		[switch]
+		$NoOverwrite,
+		
+		[Parameter()]
+		[switch]
+		$Return
     )
 
     # if path is '.', replace with server root
@@ -1257,6 +1265,11 @@ function Save-PodeRequestFile
             throw "No data for file '$($file)' was uploaded in the request"
         }
     }
+    
+	# set up filepath list
+	if($Return){
+		$filePathsList = New-Object System.Collections.Generic.List[string]
+	}
 
     # save the files
     foreach ($file in $files) {
@@ -1265,10 +1278,37 @@ function Save-PodeRequestFile
         if (Test-PodePathIsDirectory -Path $filePath) {
             $filePath = [System.IO.Path]::Combine($filePath, $file)
         }
+		
+		# add numeric suffix to file name if overwrites are not permitted
+		if($NoOverwrite -and [System.IO.File]::Exists($filePath)){
+			# set up necessary variables for looping
+			$splitPathArray = $filePath -split '\.(?=[^\\]+$)'
+			$i = 0
+			
+			# loop until suggested filepath doesn't exist
+			while([System.IO.File]::Exists($filePath)){
+				$i++
+				$tempSplitPathArray = $splitPathArray.Clone()
+				$tempSplitPathArray[0] = -join ($splitPathArray[0], " ($i)")
+				$filePath = $tempSplitPathArray -join '.'
+			}
+		}
+		
+		# add filepath to filepath list
+		if($Return){
+			$filePathsList.Add($filePath)
+		}
 
         # save the file
         $WebEvent.Files[$file].Save($filePath)
-    }
+		
+    }
+	
+	# return filepath list
+	if($Return){
+		return ,$filePathsList
+	}
+	
 }
 
 <#
@@ -1600,4 +1640,4 @@ function Add-PodeViewFolder
     # add the route(s)
     Write-Verbose "Adding View Folder: [$($Name)] $($Source)"
     $PodeContext.Server.Views[$Name] = $Source
-}
\ No newline at end of file
+}

From b6787472e8734fba06a97a313363d93856043ab9 Mon Sep 17 00:00:00 2001
From: acommonusername <130874097+acommonusername@users.noreply.github.com>
Date: Mon, 1 May 2023 01:21:13 +0200
Subject: [PATCH 2/5] Update Responses.ps1

---
 src/Public/Responses.ps1 | 76 +++++++++++++++++++++++-----------------
 1 file changed, 43 insertions(+), 33 deletions(-)

diff --git a/src/Public/Responses.ps1 b/src/Public/Responses.ps1
index 5adc560fe..eabf86420 100644
--- a/src/Public/Responses.ps1
+++ b/src/Public/Responses.ps1
@@ -1207,6 +1207,13 @@ If the Request has multiple files in, and you specify a file path, then all file
 .PARAMETER FileName
 An optional FileName to save a specific files if multiple files were supplied in the Request. By default, every file is saved.
 
+.PARAMETER NoOverwrite
+If supplied, disables overwriting already existing files, and adds a numerical suffix to the filename if necessary.
+F.x. if C:\pode\test.txt already exists and test.txt is uploaded again, it will be saved as C:\pode\test (1).txt
+
+.PARAMETER Return
+If supplied, filepaths of all saved files will be returned as a list.
+
 .EXAMPLE
 Save-PodeRequestFile -Key 'avatar'
 
@@ -1215,6 +1222,9 @@ Save-PodeRequestFile -Key 'avatar' -Path 'F:/Images'
 
 .EXAMPLE
 Save-PodeRequestFile -Key 'avatar' -Path 'F:/Images' -FileName 'icon.png'
+
+.EXAMPLE
+Save-PodeRequestFile -Key 'avatar' -Path 'F:/Images' -NoOverwrite -Return
 #>
 function Save-PodeRequestFile
 {
@@ -1232,13 +1242,13 @@ function Save-PodeRequestFile
         [string[]]
         $FileName,
 		
-		[Parameter()]
-		[switch]
-		$NoOverwrite,
+        [Parameter()]
+        [switch]
+        $NoOverwrite,
 		
-		[Parameter()]
-		[switch]
-		$Return
+        [Parameter()]
+        [switch]
+        $Return
     )
 
     # if path is '.', replace with server root
@@ -1265,11 +1275,11 @@ function Save-PodeRequestFile
             throw "No data for file '$($file)' was uploaded in the request"
         }
     }
-    
-	# set up filepath list
-	if($Return){
-		$filePathsList = New-Object System.Collections.Generic.List[string]
-	}
+
+    # set up filepath list
+    if($Return){
+        $filePathsList = New-Object System.Collections.Generic.List[string]
+    }
 
     # save the files
     foreach ($file in $files) {
@@ -1279,35 +1289,35 @@ function Save-PodeRequestFile
             $filePath = [System.IO.Path]::Combine($filePath, $file)
         }
 		
-		# add numeric suffix to file name if overwrites are not permitted
-		if($NoOverwrite -and [System.IO.File]::Exists($filePath)){
-			# set up necessary variables for looping
-			$splitPathArray = $filePath -split '\.(?=[^\\]+$)'
-			$i = 0
-			
-			# loop until suggested filepath doesn't exist
-			while([System.IO.File]::Exists($filePath)){
-				$i++
-				$tempSplitPathArray = $splitPathArray.Clone()
-				$tempSplitPathArray[0] = -join ($splitPathArray[0], " ($i)")
-				$filePath = $tempSplitPathArray -join '.'
-			}
-		}
+        # add numeric suffix to file name if overwrites are not permitted
+        if($NoOverwrite -and [System.IO.File]::Exists($filePath)){
+            # set up necessary variables for looping
+            $splitPathArray = $filePath -split '\.(?=[^\\]+$)'
+            $i = 0
+
+            # loop until suggested filepath doesn't already exist
+            while([System.IO.File]::Exists($filePath)){
+                $i++
+                $tempSplitPathArray = $splitPathArray.Clone()
+                $tempSplitPathArray[0] = -join ($splitPathArray[0], " ($i)")
+                $filePath = $tempSplitPathArray -join '.'
+            }
+        }
 		
-		# add filepath to filepath list
-		if($Return){
-			$filePathsList.Add($filePath)
-		}
+        # add filepath to filepath list
+        if($Return){
+            $filePathsList.Add($filePath)
+        }
 
         # save the file
         $WebEvent.Files[$file].Save($filePath)
 		
     }
 	
-	# return filepath list
-	if($Return){
-		return ,$filePathsList
-	}
+    # return filepath list
+    if($Return){
+        return ,$filePathsList
+    }
 	
 }
 

From f09a737fc637cbbe7587842e1e9efcca06b992b8 Mon Sep 17 00:00:00 2001
From: acommonusername <130874097+acommonusername@users.noreply.github.com>
Date: Mon, 1 May 2023 01:28:59 +0200
Subject: [PATCH 3/5] Update Responses.ps1

---
 src/Public/Responses.ps1 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Public/Responses.ps1 b/src/Public/Responses.ps1
index eabf86420..5fbb02721 100644
--- a/src/Public/Responses.ps1
+++ b/src/Public/Responses.ps1
@@ -1292,7 +1292,7 @@ function Save-PodeRequestFile
         # add numeric suffix to file name if overwrites are not permitted
         if($NoOverwrite -and [System.IO.File]::Exists($filePath)){
             # set up necessary variables for looping
-            $splitPathArray = $filePath -split '\.(?=[^\\]+$)'
+            $splitPathArray = $filePath -split '\.(?=[^\\\/]+$)'
             $i = 0
 
             # loop until suggested filepath doesn't already exist

From 48c3a1497d2557c67feac6d06a90346f8d4ca025 Mon Sep 17 00:00:00 2001
From: acommonusername <130874097+acommonusername@users.noreply.github.com>
Date: Mon, 1 May 2023 01:34:01 +0200
Subject: [PATCH 4/5] Update Responses.ps1

---
 src/Public/Responses.ps1 | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/Public/Responses.ps1 b/src/Public/Responses.ps1
index 5fbb02721..37d95644b 100644
--- a/src/Public/Responses.ps1
+++ b/src/Public/Responses.ps1
@@ -1277,7 +1277,7 @@ function Save-PodeRequestFile
     }
 
     # set up filepath list
-    if($Return){
+    if ($Return) {
         $filePathsList = New-Object System.Collections.Generic.List[string]
     }
 
@@ -1290,13 +1290,13 @@ function Save-PodeRequestFile
         }
 		
         # add numeric suffix to file name if overwrites are not permitted
-        if($NoOverwrite -and [System.IO.File]::Exists($filePath)){
+        if ($NoOverwrite -and [System.IO.File]::Exists($filePath)) {
             # set up necessary variables for looping
             $splitPathArray = $filePath -split '\.(?=[^\\\/]+$)'
             $i = 0
 
             # loop until suggested filepath doesn't already exist
-            while([System.IO.File]::Exists($filePath)){
+            while ([System.IO.File]::Exists($filePath)) {
                 $i++
                 $tempSplitPathArray = $splitPathArray.Clone()
                 $tempSplitPathArray[0] = -join ($splitPathArray[0], " ($i)")
@@ -1305,7 +1305,7 @@ function Save-PodeRequestFile
         }
 		
         # add filepath to filepath list
-        if($Return){
+        if ($Return) {
             $filePathsList.Add($filePath)
         }
 
@@ -1315,7 +1315,7 @@ function Save-PodeRequestFile
     }
 	
     # return filepath list
-    if($Return){
+    if ($Return) {
         return ,$filePathsList
     }
 	

From f093f987a526cb37b3e5f94a814fb22667786219 Mon Sep 17 00:00:00 2001
From: acommonusername <130874097+acommonusername@users.noreply.github.com>
Date: Mon, 1 May 2023 01:37:40 +0200
Subject: [PATCH 5/5] Update Responses.ps1

---
 src/Public/Responses.ps1 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Public/Responses.ps1 b/src/Public/Responses.ps1
index 37d95644b..0a80fde89 100644
--- a/src/Public/Responses.ps1
+++ b/src/Public/Responses.ps1
@@ -1224,7 +1224,7 @@ Save-PodeRequestFile -Key 'avatar' -Path 'F:/Images'
 Save-PodeRequestFile -Key 'avatar' -Path 'F:/Images' -FileName 'icon.png'
 
 .EXAMPLE
-Save-PodeRequestFile -Key 'avatar' -Path 'F:/Images' -NoOverwrite -Return
+$filePaths = Save-PodeRequestFile -Key 'avatar' -Path 'F:/Images' -NoOverwrite -Return
 #>
 function Save-PodeRequestFile
 {