Ragul
Ragul

Reputation: 512

How to get attachment thumbnail of workitem in Azure DevOps API?

I need to preview all the attachments of a workitem in compressed size (thumbnail)

I don't want to download full-size attachments.

I know currently we need to use following link

$url = https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/434?**$expand=all**&api-version=5.0

and loop and get each attachment by id.

but its downloads in full size.

Do we have any way to see compressed attachment preview first before download ?

Upvotes: 0

Views: 136

Answers (1)

Alvin Zhao - MSFT
Alvin Zhao - MSFT

Reputation: 5927

Update

Per the Get attachment REST API of Azure DevOps, it only gets the full contents from the WIT attachment files and doesn't support generating any compressed size thumbnail.

For the text contents, you may preview the information in the script as what is done like below without saving those contents into any new file.

For other contents type like images, the API itself doesn't generate a compressed size thumbnail.


Based on your requirement, I managed to preview the contents of the sample attachment files of a work item with the attament.url.

Image

Here is a sample script for your refence.

$organization = "AzureDevOpsOrgName"
$project = "TheProjectName"
$witId = "2175"
$MyPat = "xxxxxx"
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$MyPat"))
$headers = @{
    'Authorization' = 'basic ' + "$B64Pat"
    'Content-Type' = 'application/json'
}
$witURL = "https://dev.azure.com/$organization/$project/_apis/wit/workitems/$($witId)?`$expand=all&api-version=7.2-preview.3"
$wit = Invoke-RestMethod -Method Get -Uri $witURL -Headers $headers

$attachments = $wit.relations | Where-Object { $_.rel -eq 'AttachedFile' }
foreach ($attachment in $attachments) {
    Write-Host PREVIEW - $attachment.attributes.name:
    Invoke-RestMethod -Method Get -Uri $attachment.url -Headers $headers
}

Image

Upvotes: 0

Related Questions