Discussions
Eloqua Upload Image API Error In Powershell

Hi I'm trying to upload an image to Eloqua using the upload image API endpoint: /api/REST/1.0/assets/image/content .
When building this request in postman everything works fine and I'm able to upload the Image without problems. However when I use the Powershell script that Postman provides I cannot get the post to work and continue to run into this error:
[{"type":"FileError","requirement":{"type":"SizeRequirement","maxSize":52428800,"minSize":1}}]
Here is my code with the removal of a valid bearer token:
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json")
$headers.Add("Authorization", "Bearer -------")
$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$multipartFile = 'D:\KC_Events\KC_Integration\Eloqua\Images\TestImage.png'
$FileStream = [System.IO.FileStream]::new($multipartFile, [System.IO.FileMode]::Open)
$fileHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$fileHeader.Name = "file"
$fileHeader.FileName = ""
$fileContent = [System.Net.Http.StreamContent]::new($FileStream)
$fileContent.Headers.ContentDisposition = $fileHeader
$multipartContent.Add($fileContent)
$body = $multipartContent
$response = Invoke-RestMethod 'https://secure.p04.eloqua.com/api/REST/1.0/assets/image/content' -Method 'POST' -ContentType "multipart/form-data; boundary=`"$boundary`"" -Headers $headers -Body $body
$response | ConvertTo-Json
Am I missing something?
Thanks to anyone who can provide information.
Answers
-
Turned out to be a very simple solution. The Postman provided powershell doesn't populate the $fileHeader.FileName = "". All I had to do is include the file name here $fileHeader.FileName = "TestImage.png" and the powershell post request worked.