Enabling Data Streaming

Streaming supports handling large data sent from device-to-server and vice-versa.

Streaming of response data obtained from the server on a client is the ability to receive data of unlimited size via a stream. The stream is processed as the data arrives and is not needed to be stored in the device memory at any point of time. The streaming can be done in both synchronous and asynchronous invocations of the client. The streaming does not impact the server.
Server to Device Streaming: To enable server to device streaming, the application has to implement the APIs in SDMHttpRequestDelegate class. The size of the streamed data chunks can be set by using the set method on the ODPRequest object.
Note: The maximum chunk size that can be set is up to 200KB. If chunk size is not set, 100KB is considered as default value.
//Invoke the following method when response header is available to the application
(void)headersArrived:(NSMutableDictionary*)headers;


//Invoke the following method when a chunk of data is available to the application
 (void)request:(ODPRequest*)request didReceiveData:(NSData*)data;


//Invoke the following method after all chunks of a response are received and when a request is completed
 (void)requestFinished:(ODPRequest*)request;


//Invoke the following method to set the  data chunks size
[l_request setChunkSize:50000]; 
Device to Server Streaming: Application enables uploading data stream functionality by setting shouldStreamPostDataFromDisk to YES.
//Invoke the following method to enable streaming from device to server
upload_request.shouldStreamPostDataFromDisk=YES;


//Invoke the following method to provide the absolute file path on the device. This file path contains the upload data.
[upload_request setPostBodyFilePath:filePath];
Example for uploading data from device to server

     ODPRequest* upload_request = [ODPRequest requestWithURL:[NSURL URLWithString:@"http://ldcigkq.wdf.sap.corp:50080/sap/opu/odata/iwfnd/RMTSAMPLEFLIGHT/TravelagencyCollection"]];
     NSString *documentsDirectory = [NSHomeDirectory() 
                   stringByAppendingPathComponent:@"Documents"];
     NSString *filePath = [documentsDirectory 
                   stringByAppendingPathComponent:@"uploadData.xml"];
     [upload_request addRequestHeader:@"Content-Type" value:@"application/atom+xml"];
     [upload_request setRequestMethod:@"POST"];
     [upload_request setPostBodyFilePath:filePath];
     upload_request.shouldStreamPostDataFromDisk=YES;
     upload_request.allowCompressedResponse=NO;
     [upload_request setUsername:@"supuser2"];
     [upload_request setPassword:@"s3puser"];
     [upload_request startSynchronous];

Example for downloading data from server to device

ODPRequest * l_request=[ODPRequest requestWithURL:[NSURL URLWithString:@"http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/iwfnd/RMTSAMPLEFLIGHT/FlightCollection"]];
    [l_request setAllowCompressedResponse:NO];
    [l_request setUsername:@"supuser"];
    [l_request setPassword:@"s3puser"];
    [l_request setChunkSize:100000];
    [l_request setDelegate:self];
    [l_request setDidReceiveDataSelector:@selector(request:didReceiveData:)];
    [l_request setDidReceiveResponseHeadersSelector:@selector(headersArrived:)];
    [l_request setDidFinishSelector:@selector(requestFinished:)];
    [l_request startSynchronous];