Skip to content

Commit

Permalink
Merge pull request #31 from PetriAsi/develop
Browse files Browse the repository at this point in the history
Keep uft8 filenames unescaped
  • Loading branch information
PetriAsi committed Mar 19, 2023
2 parents 1215bae + 98cffcb commit 8ab2d6c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions WilmaPSWorker/Public/Send-WPSWAttachment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function Send-WPSWAttachment (){
}

Write-Verbose "Send-WPSWAttachment compose multipart content"

$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()

#content-type headers for name values makes wilma confused
Expand Down Expand Up @@ -95,6 +95,8 @@ function Send-WPSWAttachment (){
$fileHeader.FileName = $fileItem.Name
$fileContent = [System.Net.Http.StreamContent]::new($FileStream)
$fileContent.Headers.ContentDisposition = $fileHeader
#Hack to prevent filename escaping and keep uft8
($fileContent.Headers.ContentDisposition.Parameters| Where-Object { $_.Name -eq 'filename'}).Value = $fileItem.Name
if ((Split-Path -Path $fileItem.Name -Extension) -eq '.pdf' ){
$fileContent.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse("application/pdf")
} else {
Expand All @@ -118,7 +120,7 @@ function Send-WPSWAttachment (){

try {
Write-Verbose "$($WPSWSession.config.url)$basepath"
$result = Invoke-WebRequest -Method Post -Headers $Headers -Uri "$($WPSWSession.config.url)$basepath" -ContentType 'multipart/form-data' -Body $multipartContent -WebSession $WPSWSession.WilmaSession
$result = Invoke-WebRequest -Method Post -Headers $Headers -Uri "$($WPSWSession.config.url)$basepath" -ContentType 'multipart/form-data; charset=utf8' -Body $multipartContent -WebSession $WPSWSession.WilmaSession

#Add $result.content check as almost all requests are returning 200
try {$content = $result.content | ConvertFrom-Json
Expand Down

0 comments on commit 8ab2d6c

Please sign in to comment.