Windchill REST Services > Windchill REST Services Domain Capabilities > Examples for Basic REST Operations > Examples for the PTC Regulatory Master Domain > Three-Stage Upload of Attachments to a Regulatory Submission
  
Three-Stage Upload of Attachments to a Regulatory Submission
You can upload one or more attachments to a non-revisable or revisable regulatory submission.
You can upload the attachments to a non-revisable or revisable regulatory submission in three stages.
This example shows you how to upload an attachment to a revisable regulatory submission. The three stages of the uploading process are described below.
Stage 1—Specify the number of files to attach in the request body.
* 
You must first reserve the non-revisable regulatory submission to which you want to add an attachment.
You must first check out the revisable regulatory submission to which you want to add an attachment.
Use the following POST URI with the request body.
Stage 1–URI
POST /Windchill/servlet/odata/RegMstr/RegSubmission2('OR:com.ptc.qualitymanagement.regmstr.RegSubmission2:256705')/PTC.RegMstr.UploadStage1Action
Stage 1–Request Headers
Content-Type: application/json
CSRF_NONCE: <Use the value from Fetch NONCE example>
Stage 1–Request Body
{
"NoOfFiles": 1
}
Stage 1–Sample Response
{
"@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": [
12601
],
"FileNames": [
12601
]
}
]
}
Stage 2—Copy the value of the ReplicaUrl attribute from the response you get from Stage 1 and use it as the POST URI as shown below.
Stage 2–URI
POST /Windchill/servlet/WindchillGW/wt.fv.uploadtocache.DoUploadToCache_Server/doUploadToCache_Master?mk=wt.fv.uploadtocache.DoUploadToCache_Server&VaultId=241504&FolderId=241512&CheckSum=28002&sT=1613039289&sign=pd%2F3ho7xrcUOoZw61A0w6x85sVBth3xnGvv2esgYffA%3D&site=http%3A%2F%2Fvagrant.ptcnet.ptc.com%3A2280%2FWindchill%2Fservlet%2FWindchillGW&AUTH_CODE=HmacSHA256&isProxy=true&delegate=wt.fv.uploadtocache.DefaultRestFormGeneratorDelegate
Stage 2–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" 12601: 12601: 12601
----------------------------boundary
Content-Disposition: form-data; name="76030"; filename="TestFile.jpg" is content of the test file.
----------------------------boundary
* 
The CacheDescriptor_array contains the following information: <streamId>:<fileName>:<contentId>:<fileSize> where,
streamId—Specifies the unique content ID from the Stage 1 response.
fileName—Specifies the name of the file from the Stage 1 response.
contentId—Same as streamId.
fileSize—Optional. Specifies the size of the file to be uploaded in bytes.
The response from Stage 2 contains information about streamId, size of the file created, and encoded CachedContentDescriptor that is used in Stage 3 for uploading content to the regulatory submission.
Stage 2–Sample Response
{
"contentInfos": [
{
"streamId": 12601,
"fileSize": 95305,
"encodedInfo": "76035%3A2%3A150329%3A76035"
}
]
}
Stage 3—Use the following POST URI with the request body.
Stage 3–URI
POST /Windchill/servlet/odata/RegMstr/RegSubmission2('OR:com.ptc.qualitymanagement.regmstr.RegSubmission2:256705')/PTC.RegMstr.UploadStage3Action
Stage 3–Request Headers
Content-Type: application/json
CSRF_NONCE: <Use the value from Fetch NONCE example>
Stage 3–Request Body
The StreamId, FileSize, and EncodedInfo are obtained from the Stage 2 response.
{
"ContentInfo": [
{
"StreamId": 12601,
"FileSize": 95305,
"EncodedInfo": "76035%3A2%3A150329%3A76035",
"MimeType": "img/png",
"PrimaryContent": false,
"FileName": "filename"
}
]
}
The request returns the attachment ID and the file is uploaded to the specified revisable regulatory submission.