cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[Obj-C V2] How to resume uploading a large file

[Obj-C V2] How to resume uploading a large file

Wouter V.
Explorer | Level 4

 

Hi

I read the forum here, many answer to related questions point to discontinued stackoverflow documentation.

 

Specific question: How can I resume uploading a large file using the obj-c V2 API.

I am currently uploading as shown below.

 

The DBUploadTask has "cancel" and "resume" selectors. But how can these be persisted?

Should I use another upload method?

 

Is there any sample-code? 

 

Thanks

Wouter

 

 

DBUploadTask *thisTask = [[[client.filesRoutes uploadUrl:remotePath
                                                        mode:[[DBFILESWriteMode alloc] initWithOverwrite]
                                                 autorename:@(NO)
                                             clientModified:nil
                                                       mute:nil
                                             propertyGroups:nil
                                                   inputUrl:localFilePath]
                   setResponseBlock:^(DBFILESFileMetadata *result, DBFILESUploadError *routeError, DBRequestError *error)
                   {
                       if (result)
                       {
			   // finished successfully
                       }
                       else {
                           id theError = routeError ? routeError : error;
                           DebugError( @"%@", theError);
                       }
                    }]
                    setProgressBlock:^(int64_t bytesDownloaded, int64_t totalBytesDownloaded, int64_t totalBytesExpectedToDownload) {
                        DebugLog(@"\nDownloaded: %.02f KB\nTotal done: %.02f KB\nTotal expected: %02.f KB\n", (CGFloat)bytesDownloaded/1024.0f, (CGFloat)totalBytesDownloaded/1024.0f, (CGFloat)totalBytesExpectedToDownload/1024.0f);
                    }
            ];

 

4 Replies 4

Greg-DB
Dropbox Staff

What do you mean exactly when you ask "how can these be persisted?" Once you have that DBUploadTask, you can call suspend, resume, or cancel if/when desired. You can keep that object whever you want, e.g., as a property of the controller.

 

        [thisTask suspend];
...
        [thisTask resume];
...
        [thisTask cancel];

 

Also, note that for larger files (over 150 MB maximum), you should use upload sessions instead. When doing so, you can keep track of progress in between the individual calls.

Wouter V.
Explorer | Level 4

Hi Greg,

Thanks for the reply

 


What do you mean exactly when you ask "how can these be persisted?" Once you have that DBUploadTask, you can call suspend, resume, or cancel if/when desired. You can keep that object whever you want, e.g., as a property of the controller.


 

 

Yes as a property, but how can a task be persisted... between session. To disk. To run again several hours later when the user next starts the app or next has network access?

 

 

 

Also, note that for larger files (over 150 MB maximum), you should use upload sessions instead. When doing so, you can keep track of progress in between the individual calls.


 

Thanks for that link: is there any sample code that uses upload sessions?

 

Wouter

 

Greg-DB
Dropbox Staff

The single upload calls, i.e., the non-upload session methods such as uploadUrl, are not meant for use over long periods of time, as they operate using only a single HTTPS request. If you need to manage an upload over a long period of time like this, upload sessions would work better. You can store the upload session's sessionId (a String) and offset (an NSNumber) however you wish. An upload session is good for up to 48 hours.

 

I don't have a sample implementation of using upload sessions with the Objective-C SDK unfortunately. There are some other samples that can serve as a guide in this thread though.

Wouter V.
Explorer | Level 4

Thanks, that helps

Wouter

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Wouter V. Explorer | Level 4
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?