Hi,
I really hope somebody can help me understand why i'm suddently unable to upload files via the rest API. I can create issues, I can extract them, But adding attachments are not working.
The following part of my code is not working for some reason:
Invoke-RestMethod -Headers $jira_headers -Uri $uri -Method POST -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $body
The server is responding with the following message:
Object reference not set to an instance of an object.
Here is the code that is being used (variables, like strings have all be tested and the values are fine):
[string] $Filename = $rowA.FILE_NAME
[string] $templatePath = "C:\UK\JIRA_upload\FILES\" + $rowA.ID + "\"
$path = $templatePath + $rowA.FILE_NAME
if(!(Test-Path $templatePath))
{
New-Item -ItemType Directory -path $templatePath
}
[System.IO.File]::AppendAllText($path, $rowA.FILE_CONTENT)
$jira_headers = @{
"Authorization" = $basicAuth
"X-Atlassian-Token" = "nocheck"
}
$uri = "$target/rest/api/2/issue/$jid/attachments"
$myfile = $path
$fileBytes = [System.IO.File]::ReadAllBytes($myfile);
$fileEnc = [System.Text.Encoding]::GetEncoding('UTF-8').GetString($fileBytes);
$boundary = [guid]::NewGuid().ToString()
$LF = "`r`n";
$body = (
"--$boundary",
"Content-Disposition: form-data; name=`"file`"; filename=`"$Filename`"",
"Content-Type: application/octet-stream$LF",
$fileEnc,
"--$boundary--$LF"
) -join $LF
$serverResponse = Invoke-RestMethod -Headers $jira_headers -Uri $uri -Method POST -ContentType "multipart/form-data; boundary=`"$boundary`"" -Body $body
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.