3.6.5.1 Upload Scenario
The client MUST do the following:
Create Session:
The client MUST send a PUT request on Create Session resource, as specified in section 3.4.5.1.1, by using the URI format "HostURLPrefix/Sync/SyncClientVersion/Session". The x-ecs-partnershipID header MUST be set to SyncTargetPartnershipId. The x-ecs-devicename header MUST be set to an implementation-specific string. The client MUST set ClientID in the request body to Client_ID.
The calling application intends to:
Commit SyncIds on the server since last sync, if Type is set to 0x01.
Commit entire list of SyncIds available on the client, if Type is set to 0x03.
If the server responds with a status code of 200, the client MUST construct the SessionLocationURL using the x-ecs-session-id header as follows:
"HostUrlPreifx/Sync/SyncClientVersion/Session/<x-ecs-session-id>/"
Get Sync Batch Parameters from Server:
The client MUST send a GET request on the Sync Batch Parameters resource, as specified in section 3.4.5.2.1, by using the URI format "SessionLocationURL/SyncBatchParameters". The x-ecs-partnershipID header MUST be set to SyncTargetPartnershipId.
If the server responds with a status code of 200, the client MUST store the entries in the response body as follows:
SyncBatchServerKnowledge is set to SyncKnowledge.
UploadBatchLimits is set to BatchLimits.
Inform Server to Prepare Batch:
The client MUST check for the changes in the underlying object store and update FileMetadataTable as follows:
If an entry in the FileMetadataTable with ObjectStoreID already exists and the file is deleted from the object store, delete this entry from FileMetadataTable.
If an entry in the FileMetadataTable with ObjectStoreID already exists and the file is not deleted from the object store, update the metadata entry.
If there is a change in file content, generate a GUID and assign it to FileStreamId.
Otherwise, create an entry, initialize it as follows, and add the entry to FileMetadataTable.
Find an entry with the ObjectStoreID of the parent and set ParentId to FileId of this entry.
Set ObjectStoreID as the unique identifier of the object store.
Generate a SYNC_GID structure and assign it to FileId.
Generate a GUID and assign it to FileStreamId.
Set FileAttributes to the object store attributes.
Set NamespaceChangeTime, AttributeChangeTime, CreatedTime, and ModifiedTime to the current time.
Set ContentSize as the file size.
Set FileName to the name of the file.
Set OriginatingDeviceName to the name of this device.
The client MUST send a PUT request on the Prepare Batch resource, as specified in section 3.4.5.3.1, by using the URI format "SessionLocationURL/PrepareBatch/<BatchIndex>". The BatchIndex in the URI MUST be set to a value that uniquely identifies the batch within the session. Using the SyncBatchServerKnowledge, FileMetadataTable, and the application-supplied version information, the client MUST construct a VECTOR_FILE_INFO_INPUT_ENTRY structure and insert the same as the FileVector entry in the request body.
If the server responds with a status code of 200, the client MUST store the information in FILE_INFO_ENTRY structures in FileList in the response body as follows:
If the ProtocolType is 1, create a new UploadFile object and initialize it as follows:
UploadFile.SyncId MUST be set to SyncItemId.
Insert the UploadFile object into the global UploadFileList.
Data Transfer:
From each entry in UploadFileList, the client MUST construct a VECTOR_UPLOAD_ENTRY structure and MUST send a PUT request on Upload Data resource, as specified in section 3.5.5.1.1, by using the URI format "SessionLocationURL/UploadData".
Commit Change Batch:
The client MUST send a PUT request on the Upload Batch resource, as specified in section 3.4.5.4.1, by using the URI format "SessionLocationURL/UploadBatch/<BatchIndex>". The BatchIndex in the URI MUST be set to an implementation-specific value that identifies the batch to be uploaded. The SerializedSyncBatch in the request body MUST be set to an opaque binary stream representing the change batch. If Session.SessionType in the request is 0x03, SyncMetadata of SerializedSyncBatch in the request body contains the entire list of SyncIds on the client.
For each UploadFile in UploadFileList, the client MUST update UploadFile.CommitStatus to the Status entry returned in the FILE_STATUS_ENTRY structure.
Delete Session:
The client MUST send a DELETE request on Delete Session resource, as specified in section 3.4.5.5.1, by using the URI format "SessionLocationURL".
The client MUST clear all entries in the UploadFileList.