Uploading Content for a Document
This example shows you how to upload content for a document in the following cases:
Using a local file
Using URL data
Using external data
* 
Although Security Labels cannot be specified as part of the content upload using the WRS Document Management domain., all security label constraints for file vaulting are respected for WRS.
Use the following POST URI with the request body.
Using a Local File
The content can be uploaded in the following stages:
Stage1—POST URI
POST /Windchill/servlet/odata/DocMgmt/Documents('OR:wt.doc.WTDocument:48796581')/PTC.DocMgmt.UploadStage1Action HTTP/1.1
Stage 1—Request Headers
Content-Type: application/json
CSRF_NONCE: <Use the value from Fetch NONCE example>
Stage1—Request Body
{
"NoOfFiles": 3
}
Stage1—Sample Output
{
"@odata.context": "$metadata#CacheDescriptor",
"value": [
{
"ID": null,
"ReplicaUrl": "https://windchill.ptc.com/Windchill/servlet/WindchillGW/wt.fv.uploadtocache.DoUploadToCache_Server/doUploadToCache_Master?mk=wt.fv.uploadtocache.DoUploadToCache_Server&VaultId=150301&FolderId=150329&CheckSum=456186&sT=1507542170&sign=Ca4ouGGOZiopnqbd4mbUVg%3D%3D&site=https%3A%2F%2Fwindchill.ptc.com%2FWindchill%2Fservlet%2FWindchillGW&AUTH_CODE=HmacMD5&isProxy=true&delegate=wt.fv.uploadtocache.DefaultRestFormGeneratorDelegate",
"MasterUrl": "https://windchill.ptc.com/Windchill/servlet/WindchillGW",
"VaultId": 150301,
"FolderId": 150329,
"StreamIds": [
76030,
76032,
76031
],
"FileNames": [
76030,
76032,
76031
]
}
]
}
Stage2—The HTTP request for Stage2 must be constructed from ReplicaUrl attribute which is retrieved from Stage1.
* 
Make sure the request body maintains the sequence of multipart entities.
Stage2—POST URI
https://windchill.ptc.com/Windchill/servlet/WindchillGW/wt.fv.uploadtocache.DoUploadToCache_Server/doUploadToCache_Master?mk=wt.fv.uploadtocache.DoUploadToCache_Server&VaultId=150301&FolderId=150329&CheckSum=456186&sT=1507542170&sign=Ca4ouGGOZiopnqbd4mbUVg%3D%3D&site=https%3A%2F%2Fwindchill.ptc.com%2FWindchill%2Fservlet%2FWindchillGW&AUTH_CODE=HmacMD5&isProxy=true&delegate=wt.fv.uploadtocache.DefaultRestFormGeneratorDelegate
Stage 2—Request Headers
Content-Type: multipart/form-data; boundary=-----------------------------boundary
Stage2—Request Body
-----------------------------boundary
Content-Disposition: form-data; name="Master_URL"
https://windchill.ptc.com/Windchill/servlet/WindchillGW
----------------------------boundary
Content-Disposition: form-data; name="CacheDescriptor_array"
76030: 76030: 76030; 76031: 76031: 76031; 76032: 76032: 76032;
----------------------------boundary
Content-Disposition: form-data; name="76030"; filename="TestFile1.txt"
is content of test file 1.
----------------------------boundary
Content-Disposition: form-data; name="76031"; filename="TestFile3.txt"
is content of test file 3.
----------------------------boundary
Content-Disposition: form-data; name="76032"; filename="TestFile2.txt"
is content of test file 2.
----------------------------boundary
* 
The CacheDescriptor_array contains the following information <streamid>:<filename>:<contentid>:<filesize> where,
streamid—Specifies the unique content ID from the Stage1 response.
filename—Specifies the name of the file from the Stage1 response.
contentid—Same as streamid.
filesize—Specifies size of the file to be uploaded in bytes (Optional).
The response from Stage2 contains information about the streamId, size of the file created, and encoded CachedContentDescriptor, which is used in Stage3 for uploading content to the document.
Stage2—Sample Output
{
"contentInfos": [
{
"streamId": 76030,
"fileSize": 2,
"encodedInfo": "76035%3A2%3A150329%3A76035"
},
{
"streamId": 76031,
"fileSize": 2,
"encodedInfo": "76034%3A2%3A150329%3A76034"
},
{
"streamId": 76032,
"fileSize": 2,
"encodedInfo": "76033%3A2%3A150329%3A76033"
}
]
}
Stage3—POST URI
POST /Windchill/servlet/odata/DocMgmt/Documents('OR:wt.doc.WTDocument:48796581')/PTC.DocMgmt.UploadStage3Action HTTP/1.1
Stage 3—Request Headers
Content-Type: application/json
CSRF_NONCE: <Use the value from Fetch NONCE example>
Stage3—Request body
{
"ContentInfo" : [
{
"StreamId" :76030,
"EncodedInfo" : "76033%3A2%3A150329%3A76033",
"FileName" : "DesignSpec.doc",
"PrimaryContent" : true,
"MimeType" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"FileSize" : 2
},
{
"StreamId" :76031,
"EncodedInfo" : "76035%3A2%3A150329%3A76035",
"FileName" : "ReferenceDoc1.doc",
"PrimaryContent" : false,
"MimeType" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"FileSize" : 2
},
{
"StreamId" :76032,
"EncodedInfo" : "76034%3A2%3A150329%3A76034",
"FileName" : "ReferenceDoc2.doc",
"PrimaryContent" : false,
"MimeType" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"FileSize" : 2
}
]
}
Using a URL Data
To create or update primary content from URL data, use the following PUT URI with the request body.
URI
PUT /Windchill/servlet/odata/DocMgmt/Documents('OR:wt.doc.WTDocument:2626068')/PrimaryContent HTTP/1.1
Request Headers
Content-Type: application/json
CSRF_NONCE: <Use the value from Fetch NONCE example>
Request Body
{
"UrlLocation" :"https://www.ptc.com",
"DisplayName" : "Test_PrimaryContent"
}
Using External Storage
To create or update the primary content from external storage, use the following PUT URI with the request body.
URI
PUT /Windchill/servlet/odata/DocMgmt/Documents('OR:wt.doc.WTDocument:2626068')/PrimaryContent HTTP/1.1
Request Headers
Content-Type: application/json
CSRF_NONCE: <Use the value from Fetch NONCE example>
Request Body
{
"ExternalLocation" :"TestExternalLocation",
"DisplayName" : "TestExternalLocation_DisplayName"
}
To create new attachments, use the following POST URI with the request body.
URI
POST /Windchill/servlet/odata/DocMgmt/Documents('OR:wt.doc.WTDocument:2626099')/Attachments HTTP/1.1
Request Headers
Content-Type: application/json
CSRF_NONCE: <Use the value from Fetch NONCE example>
Request Body
{
"ExternalLocation" :"TestExternalLocation",
"DisplayName" : "TestExternalLocation"
}
To update existing attachments, use the following PUT URI with the request body.
URI
PUT /Windchill/servlet/odata/DocMgmt/Documents('OR:wt.doc.WTDocument:2626099')/Attachments('OR:wt.content.ExternalStoredData:2626811') HTTP/1.1
Request Body
{
"ExternalLocation" :"TestExternalLocation_Update",
"DisplayName" : "TestExternalLocation_Update"
}
Was this helpful?