Internet Explorer is no longer supported. Many things will still work, but your experience will be degraded and some things won't function. Please use a modern browser such as Edge, Chrome, or Firefox.

Upload Asset File

view on GitHub

The Upload Asset File is available as both a pgutil command and an HTTP Request, and will create a new file in the asset directory, or overwrite an existing one.

Command Specification (CLI)

The assets upload command is used to upload a file to the asset directory.

The --target-path and --file options are always required. The --feed option is required if there is no default feed configured.

Uploading a file requires the asset directory (e.g. MyAssetDirectory), the target folder in the asset directory to upload to (e.g. uploaded-files), and the path of the file to upload (e.g. C:\Inedo\data-files\download-stats.txt):

pgutil assets upload --feed=myAssetDirectory --target-path=uploaded-files/download-stats.txt --file=C:\Inedo\data-files\download-stats.txt

The --partsize option is required when multipart uploading, and states the size of each part.

Uploading a mutipart file requires the asset directory (e.g. MyAssetDirectory), the target folder in the asset directory to upload to (e.g. uploaded-files), the path of the file to upload (e.g. C:\Inedo\data-files\download-stats.txt) and the size in mb of the part size of each upload (e.g. 2048 for a 2gb file):

pgutil assets upload --feed=myAssetDirectory --target-path=uploaded-files/download-stats.txt --file=C:\Inedo\data-files\download-stats.txt --partsize=2048

HTTP Request Specification

This HTTP request uses PUT, POST and PATCH requests. The behaviour is determined by the request used:

  • PUT will only upload a file if it doesn't already exist
  • POST will create a file in the destination if it doesn't currently exist, or overwrite any existing file with the same name
  • PATCH will only upload the file if a file with the same name currently exists, overwriting it

To create or overwrite a file, PUT, POST or PATCH to the URL with the AssetDirectoryName and path to the file. If specified, the Content-Type header will be stored for the file.

PUT/POST/PATCH /endpoints/«AssetDirectoryName»/content/«path_to_file»

If the request specifies a folder that does not currently exist, the folder will be created.

Multi-part Upload: Large Files

There is an HTTP request that can be used for very large (2GB+) files. Please see the Multipart Asset File Upload page for this.

HTTP Response Specification

Response Details
201 (Success) the file is saved to the asset directory
400 (File Already Exists) indicates that the file already exists
401 (Authentication Required) indicates a missing, unknown, or unauthorized API Key

Sample Usage Scripts

Upload all files in a folder (Powershell)

This script uploads all files within a folder, C:\Proget\upload-files to a folder, uploaded, in an asset directory, internal-files:

$apiKey = "a1b2c3d4e5"
$baseUrl = "https://proget.corp.local"
$assetdirectory = "internal-files"
$folder = "uploaded"
$localFolder = "C:\Proget\upload-files"

$headers = @{
    "Content-Type" = "application/octet-stream"
    "X-ApiKey" = $apiKey
}

Get-ChildItem -Path $localFolder | ForEach-Object {
    $fileName = $_.Name
    $apiEndpoint = "$baseUrl/$assetdirectory/content/$folder/$fileName"
    $fileContent = [System.IO.File]::ReadAllBytes($_.FullName)

    Invoke-RestMethod -Uri $apiEndpoint -Method Put -Headers $headers -Body $fileContent -ContentType "application/octet-stream"

    Write-Host "File '$fileName' uploaded to $apiEndpoint"
}

Example Output:

File 'assetcontent.bin' uploaded to https://proget.corp.local/endpoints/internal-files/content/uploaded/assetcontent.bin
File 'readme.txt' uploaded to https://proget.corp.local/endpoints/internal-files/content/uploaded/readme.txt
File 'logo.png' uploaded to https://proget.corp.local/endpoints/internal-files/content/uploaded/logo.png
...
...