Issue #1096 - Add Save-PodeRequestFile functionality - disable overwrite and return filepaths #1097
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
Added functionality to make it possible to disable overwriting files, and instead add a numerical suffix to the filename if it already exists in the directory. Enabled via Switch parameter.
Added functionality to make it possible to return a list of filepaths of the uploaded files. Enabled via Switch parameter.
Help comment updated to include parameters and an example.
Related Issue
Resolves #1096
Examples
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.
Usage
$filePaths = Save-PodeRequestFile -Key 'avatar' -Path 'F:/Images' -NoOverwrite -Return
Result
In the above example, if F:/Images already contains test.jpg and you're uploading the files test.jpg and asdf.jpg. test.jpg will be saved as test (1).jpg and asdf.jpg as asdf.jpg, the function will then return a list containing the following filepaths:
F:/Images\test (1).jpg
F:/Images\asdf.jpg