Skip to content

Instantly share code, notes, and snippets.

@TiloGit
Last active October 8, 2025 06:18
Show Gist options
  • Save TiloGit/f360d0ff2f21b08789064c4528e07b99 to your computer and use it in GitHub Desktop.
Save TiloGit/f360d0ff2f21b08789064c4528e07b99 to your computer and use it in GitHub Desktop.
Simple CMIS test. create folder and create document
#### create Folder
# Generate timestamp
$myDate = get-date -uformat "%Y-%m-%d_%s"
$folderName = "tilo_folder_$myDate"
# Define URL and credentials
$url = "http://99.99.97.146:8077/cmis/browser/Y8/root"
$pair = "admin:mypass"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
}
# Define form data as a hashtable
$formData = @{
"cmisaction" = "createFolder"
"succinct" = "true"
"propertyId[0]" = "cmis:objectTypeId"
"propertyValue[0]" = "cmis:folder"
"propertyId[1]" = "cmis:name"
"propertyValue[1]" = $folderName
}
# Send POST request
Invoke-WebRequest -Uri $url -Method Post -Body $formData -Headers $Headers
##############
### create file in CMIS
##############
# Generate timestamp
$myDate = Get-Date -UFormat "%Y-%m-%d_%s"
# Define URL and credentials
$url = "http://99.99.97.146:8077/cmis/browser/Y8/root"
$pair = "admin:mypass123"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$boundary = "$([System.Guid]::NewGuid().ToString('N'))"
##generate payload
$payload = @"
--$boundary
Content-Disposition: form-data; name="cmisaction"
createDocument
--$boundary
Content-Disposition: form-data; name="propertyId[0]"
cmis:name
--$boundary
Content-Disposition: form-data; name="propertyValue[0]"
test_$myDate.txt
--$boundary
Content-Disposition: form-data; name="propertyId[1]"
cmis:objectTypeId
--$boundary
Content-Disposition: form-data; name="propertyValue[1]"
cmis:document
--$boundary
Content-Disposition: form-data; name="media"; filename="test_$myDate.txt"
Content-Type: text/plain
test tilo here at $myDate
--$boundary--
"@
$payload = $payload -replace "`n","`r`n"
Invoke-RestMethod -Uri $url `
-Method Post `
-Headers @{ Authorization = $basicAuthValue; "Content-Type" = "multipart/form-data; boundary=$boundary" } `
-Body $payload
##create folder below
myDate=$(date +"%Fat%s")
curl -u admin:mypass -X POST http://99.99.97.146:8077/cmis/browser/Y8/root -d \
"cmisaction=createFolder" -d \
"succinct=true" -d \
"propertyId[0]=cmis:objectTypeId" -d \
"propertyValue[0]=cmis:folder" -d \
"propertyId[1]=cmis:name" -d \
"propertyValue[1]=tilotestfolder_$myDate"
##create file below
myDate=$(date +"%Fat%s")
echo "test tilo here at $myDate" > test-tilo.txt
curl -u admin:mypass \
-X POST \
-H "Content-Type: multipart/form-data" \
-F "cmisaction=createDocument" \
-F "propertyId[0]=cmis:name" \
-F "propertyValue[0]=test_$myDate.txt" \
-F "propertyId[1]=cmis:objectTypeId" \
-F "propertyValue[1]=cmis:document" \
-F "[email protected]" \
http://99.99.97.146:8077/cmis/browser/Y8/root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment