- 04 Jan 2024
- 2 Minutes to read
- Print
- DarkLight
- PDF
Upload File Endpoint
- Updated on 04 Jan 2024
- 2 Minutes to read
- Print
- DarkLight
- PDF
The Upload File is an endpoint in ProGet's Asset Directory API. It creates a new file in the asset directory, or overwrite an existing one. If specified, the Content-Type
header will be stored for the file.
This example uploads a file named log_data.bin
from C:\ProGet
, authenticating with the API key abc12345
:
curl -X PUT -H "Content-Type: application/octet-stream" --header "X-ApiKey: abc12345" --data-binary "@C:\ProGet\log_data.bin" https://proget.corp.local/endpoints/internal-files/content/log_data.bin
This endpoint uses PUT
, POST
and PATCH
requests. The endpoint behavior is determined by the request used:
PUT
will only upload a file if it doesn't already existPOST
will create a file in the destination if it doesn't currently exist, or overwrite any existing file with the same namePATCH
will only upload the file if a file with the same name currently exists, overwriting it
There is also a Multipart Upload API that can be used for very large (2GB+) files.
Request Specification
To create or overwrite a file, PUT
, POST
or PATCH
to the URL with the AssetDirectoryName
and path to the file.
PUT/POST/PATCH /endpoints/«AssetDirectoryName»/content/«path_to_file»
If the request specifies a subfolder that does not currently exist, the subfolder will be created.
Uploading a new file requires the asset directory name (e.g. myAssetDirectory
) and the file name (e.g. mycontent.bin
)
PUT /endpoints/myAssetDirectory/content/mycontent.bin
«mycontent.bin»
Uploading a new file, or overwriting a currently existing file requires the asset directory name (e.g. myAssetDirectory
) and the file name (e.g. mycontent.bin
)
POST /endpoints/myAssetDirectory/content/mycontent.bin
«mycontent.bin»
Overwriting a currently existing file requires the asset directory name (e.g. myAssetDirectory
) and the file name (e.g. mycontent.bin
)
PATCH /endpoints/myAssetDirectory/content/example.txt
«mycontent.bin»
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
:
This can be used when bulk uploading individual files located in a folder. For a more efficient solution of uploading a batch of files within an archive, use our Import Archive endpoint.
$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
...
...