Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: missing content-type header #2

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions Private/Invoke-AzureStorageBlobUploadFinalize.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ function Invoke-AzureStorageBlobUploadFinalize {
Finalize upload of chunks of the .intunewin file into Azure Storage blob container.

This is a modified function that was originally developed by Dave Falkus and is available here:
https://github.com/microsoftgraph/powershell-intune-samples/blob/master/LOB_Application/Win32_Application_Add.ps1
https://github.com/microsoftgraph/powershell-intune-samples/blob/master/LOB_Application/Win32_Application_Add.ps1

.NOTES
Author: Nickolaj Andersen
Contact: @NickolajA
Created: 2020-01-04
Updated: 2020-01-04
Updated: 2024-05-29

Version history:
1.0.0 - (2020-01-04) Function created
#>
1.0.1 - (2024-05-29) Added content-type header to the REST request to ensure correct handling of the request body (thanks to @tjgruber)
#>
param(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
Expand All @@ -27,17 +28,25 @@ function Invoke-AzureStorageBlobUploadFinalize {
[ValidateNotNullOrEmpty()]
[System.Object]$ChunkID
)

$Uri = "$($StorageUri)&comp=blocklist"
$XML = '<?xml version="1.0" encoding="utf-8"?><BlockList>'
foreach ($Chunk in $ChunkID) {
$XML += "<Latest>$($Chunk)</Latest>"
}
$XML += '</BlockList>'

try {
$WebResponse = Invoke-RestMethod -Uri $Uri -Method "Put" -Body $XML -ErrorAction Stop
}
catch {
Write-Warning -Message "Failed to finalize Azure Storage blob upload. Error message: $($_.Exception.Message)"
}
}

$XML = '<?xml version="1.0" encoding="utf-8"?><BlockList>'

foreach ($Chunk in $ChunkID) {
$XML += "<Latest>$($Chunk)</Latest>"
}

$XML += '</BlockList>'

$Headers = @{
"content-type" = "text/plain; charset=UTF-8"
}

try {
$WebResponse = Invoke-RestMethod -Uri $Uri -Method "Put" -Body $XML -Headers $Headers -ErrorAction Stop
}
catch {
Write-Warning -Message "Failed to finalize Azure Storage blob upload. Error message: $($_.Exception.Message)"
}
}