I need to upload file to Azure DevOps repository using rest api and power shell scripts. I did this:
$token = "token"
$authHeader = @{Authorization = 'Basic ' [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($token)")) }
$folderPath = "C:/"
$fileName = "TestTXT.txt"
$body = [System.IO.File]::ReadAllBytes("$folderPath/$fileName")
$org = "orgName"
$project = "projectName"
$createAttachmetUrlTemplate = "https://dev.azure.com/$org/$project/_apis/wit/attachments?fileName={fileName}&api-version=5.0"
$postUrl = $createAttachmetUrlTemplate -replace "{filename}", $fileName
$result = Invoke-RestMethod -Uri $postUrl -Method Post -ContentType "application/json" -Headers $authHeader -Body $body
I have got as result id and url accordingly
But there isn't any new file in my repo. Where is it? What is wrong? How can I store files in my repo?
CodePudding user response: