Skip to content
This repository was archived by the owner on Apr 18, 2023. It is now read-only.

Commit 5e02b0d

Browse files
author
Vikas Dadheech
committed
Add usage docs for page iterator and large file upload
1 parent f0274de commit 5e02b0d

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

Docs/Tasks/LargeFileUpload.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Large File Upload Task - Uploading large files to OneDrive.
2+
3+
This task can be used for of onedrive's [Upload large files with an upload session](https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/driveitem_createuploadsession) feature.
4+
5+
## Creating the client instance
6+
7+
Refer [this part](https://github.com/microsoftgraph/msgraph-sdk-objc#how-to-use-sdk) of Readme file and follow the steps to create an HTTP Client configured with authentication provider.
8+
9+
## Uploading the file
10+
11+
Once you have an MSHTTPClient instance you just need to use `MSGraphOneDriveLargeFileUploadTask` class in below fashion to successfully upload the file:
12+
```
13+
//Get file url
14+
NSURL *fileURL = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"LargeFileUploadResource" ofType:@".bmp"]];
15+
NSError *fileReadError;
16+
//Create file data
17+
NSData *fileData = [NSData dataWithContentsOfFile:[fileURL absoluteString] options:kNilOptions error:&fileReadError];
18+
if(!fileReadError)
19+
{
20+
//Create an MSGraphOneDriveLargeFileUploadTask.
21+
[MSGraphOneDriveLargeFileUploadTask createOneDriveLargeFileUploadTaskWithHTTPClient:httpClient fileData:fileData fileName:@"LargeFile" filePath:@"Documents" andChunkSize:5*1024*1024 withCompletion:^(MSGraphOneDriveLargeFileUploadTask *fileUploadTask, NSData *data, NSURLResponse *response, NSError *error) {
22+
if(error)
23+
{
24+
//Handle any error which might have occurred during upload session creation
25+
NSLog(@"There was some error while creating upload session %@",error);
26+
}
27+
else if([(NSHTTPURLResponse *)response statusCode] == 200 && fileUploadTask)
28+
{
29+
//Use successfully created fileUploadTask to upload the file.
30+
[fileUploadTask uploadWithCompletion:^(NSData *data, NSURLResponse *response, NSError *error) {
31+
if(!error)
32+
{
33+
NSLog(@"Response from server %@",[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]);
34+
}
35+
}];
36+
}
37+
}];
38+
}
39+
```
40+

Docs/Tasks/PageIterator.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# PageIterator
2+
3+
This task enables the consumers of the SDK to iterate through paged collections in a simplified manner.
4+
5+
To understand the objectives and requirements for this feature in more detail, please refer [PageIterator](https://github.com/microsoftgraph/msgraph-sdk-design/blob/master/tasks/PageIteratorTask.md).
6+
7+
## Usage
8+
9+
### Creating the client instance
10+
11+
Refer [this part](https://github.com/microsoftgraph/msgraph-sdk-objc#how-to-use-sdk) of Readme file and follow the steps to create an HTTP Client configured with authentication provider.
12+
13+
### Using the MSPageIterator class
14+
//Create a request for the API which will have paged collection response. For example:/me/messages
15+
NSMutableURLRequest *messageRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/messages?$top=10"]]];
16+
17+
//Create a data task to get the initial response
18+
MSURLSessionDataTask *dataTask = [httpClient dataTaskWithRequest:messageRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
19+
if(!error){
20+
__block int itemCount = 0;
21+
//If there is no error, use MSPageIterator instance to perform intra-page iteration and then onwards inter-page iteration.
22+
MSPageIterator *pageIterator = [[MSPageIterator alloc] initWithData:data client:httpClient andIteratorBlock:^(NSDictionary *itemDictionary, BOOL *stop) {
23+
//The itemDictionary in callback block corresponds to individual message in the list.
24+
if(itemCount == 21){
25+
//You can stop the iteration in below fashion.
26+
*stop = TRUE;
27+
}
28+
itemCount++;
29+
}];
30+
//Start the iteration
31+
[pageIterator iterate];
32+
}
33+
}];
34+
[dataTask execute];
35+
```

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,5 @@ And that's it. You have now successfully made call to graph server asking inform
166166
## Usage Resources
167167

168168
* [Batching](/Docs/Content/Batching.md)
169+
* [Page Iterator](/Docs/Tasks/PageIterator.md)
170+
* [Large File Upload Task](/Docs/Tasks/LargeFileUpload.md)

0 commit comments

Comments
 (0)