Coder Social home page Coder Social logo

Comments (1)

aclev avatar aclev commented on August 16, 2024

Hi @vinceplusplus The SDK does not currently support resumable item upload directly however you can still use the SDK to create a resumable session and upload fragments to that session.

To do this you will first need to call

ODChunkedUploadSessionDescriptor *sessionDescriptor = [[ODChunkedUploadSessionDescriptor alloc] init];
sessionDescriptor.name = self.currentItem.name;
ODCreateItemSessionRequest *request = [[[[self.client drive] items:self.currentItem.id] createSessionWithItem:sessionDescriptor] request] 
[request executeWithCompletion:^(ODUploadSession *response, NSError *error){
    NSURL *fileURL = [NSURL URLWithString:@"path/to/file"];
    // You must write getNextRange yourself, note that according to the documentation
    // This should be somewhere between 5-10 MiB and if possible a multiple of 320 KiB
    NSRange startRange = [self getNextRange:fileURL start:0];
   //You must write sendFragment yourself
    [self sendFragment:[NSURL URLWithString:response.uploadUrl] withFile:[NSURL URLWithString:@"path/to/fil"] range:startRange];
}];

Send fragment would look something like:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:uploadUrl];
 [self.client.authProvider appendAuthHeaders:request completion:^(NSMutableURLRequest *requestToSend, NSError *error){
     if (requestToSend){
        NSData *fragment = [self getFragmentFromFile:fileURL withRange:byteRange];
        [self appendContentHeaders:requestToSend withFile:fileURL range:byteRange];
        [[self.client.httpProvider  uploadTaskWithRequest:requestToSend fromData:fragment progress:nil completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){
              if (((NSHTTPURLResponse*)response).statusCode == 202){
                    NSRange nextRange = [self getNextRange:fileURL fromResponse:response :data];
                    [self sendFragment:uploadUrl withFile:fileURL range:nextRange];
                }
        }] resume];
    }
}];

Make sure to take a look at the resumable upload documentation For specifics about fragment size and some other notes. Supporting fragment upload fully in the SDK is on our radar, and hopefully we will implement it in the future.

from onedrive-sdk-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.