<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Uploading a file to Dropbox in chunks using Objective C in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Uploading-a-file-to-Dropbox-in-chunks-using-Objective-C/m-p/251512#M14473</link>
    <description>&lt;P&gt;This is maybe a very simple question, but I'm looking for an example how to upload a file to Dropbox using Objective C on iOS. For small files this is rather straightforward, but for large files it's more difficult. Is there any simple example on the web how to use: uploadSessionStart, uploadSessionAppendV2 and uploadSessionFinish?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas welcome!&lt;/P&gt;</description>
    <pubDate>Wed, 29 May 2019 09:17:35 GMT</pubDate>
    <dc:creator>Bjorn1</dc:creator>
    <dc:date>2019-05-29T09:17:35Z</dc:date>
    <item>
      <title>Uploading a file to Dropbox in chunks using Objective C</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Uploading-a-file-to-Dropbox-in-chunks-using-Objective-C/m-p/251512#M14473</link>
      <description>&lt;P&gt;This is maybe a very simple question, but I'm looking for an example how to upload a file to Dropbox using Objective C on iOS. For small files this is rather straightforward, but for large files it's more difficult. Is there any simple example on the web how to use: uploadSessionStart, uploadSessionAppendV2 and uploadSessionFinish?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas welcome!&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:17:35 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Uploading-a-file-to-Dropbox-in-chunks-using-Objective-C/m-p/251512#M14473</guid>
      <dc:creator>Bjorn1</dc:creator>
      <dc:date>2019-05-29T09:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: Uploading a file to Dropbox in chunks using Objective C</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Uploading-a-file-to-Dropbox-in-chunks-using-Objective-C/m-p/251545#M14474</link>
      <description>&lt;P&gt;We don't have an example for using upload sessions in the API v2 Objective-C SDK unfortunately,&amp;nbsp;but I'll pass this along as a request for one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have some samples for other languages though, which may still be useful, since the logic is the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, a simple implementation in Python:&lt;/P&gt;
&lt;PRE&gt;f = open(file_path)
file_size = os.path.getsize(file_path)

CHUNK_SIZE = 8 * 1024 * 1024

if file_size &amp;lt;= CHUNK_SIZE:

    print dbx.files_upload(f.read(), dest_path)

else:

    upload_session_start_result = dbx.files_upload_session_start(f.read(CHUNK_SIZE))
    cursor = dropbox.files.UploadSessionCursor(session_id=upload_session_start_result.session_id,
                                               offset=f.tell())
    commit = dropbox.files.CommitInfo(path=dest_path)

    while f.tell() &amp;lt; file_size:
        if ((file_size - f.tell()) &amp;lt;= CHUNK_SIZE):
            print dbx.files_upload_session_finish(f.read(CHUNK_SIZE),
                                            cursor,
                                            commit)
        else:
            dbx.files_upload_session_append(f.read(CHUNK_SIZE),
                                            cursor.session_id,
                                            cursor.offset)
            cursor.offset = f.tell()

f.close()&lt;/PRE&gt;
&lt;P&gt;Here's a longer example in Swift that splits out every error case:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;import UIKit
import SwiftyDropbox

class ViewController: UIViewController {

    // filled in later in doUpload:
    var fileHandle : NSFileHandle? = nil
    var data : NSData? = nil

    let chunkSize = 8 * 1024 * 1024  // 8 MB
    var offset = 0
    var sessionId = ""

    // replace this with your desired destination path:
    let destPath = "/SwiftyDropbox_upload.txt"

    override func viewDidLoad() {
        super.viewDidLoad()

        Dropbox.authorizedClient = DropboxClient(...)

        doUpload()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func doUpload() {

        // replace this with the path to the file you want to upload
        let filePath = "/path/to/file"
        print("Getting file at \(filePath) for uploading...")
        fileHandle = NSFileHandle.init(forReadingAtPath: filePath)!

        print("Using chunked uploading with chunk size \(chunkSize)...")
        uploadFirstChunk()

    }

    func uploadFirstChunk() {
        data = fileHandle!.readDataOfLength(chunkSize)
        let size = data!.length
        print("Have \(size) bytes to upload.")
        Dropbox.authorizedClient!.files.uploadSessionStart(input:data!)
            .response { response, error in
                if let result = response {
                    self.sessionId = result.sessionId
                    self.offset += size
                    print("So far \(self.offset) bytes have been uploaded.")
                    self.uploadNextChunk()
                } else if let callError = error {
                    print("uploadSessionStart failed")
                    switch callError as CallError {
                    case .RouteError(let error, let requestId):
                        print("RouteError[\(requestId)]: \(error)")
                    case .BadInputError(let message, let requestId):
                        print("BadInputError[\(requestId)]: \(message)")
                    case .HTTPError(let code, let message, let requestId):
                        print("HTTPError[\(requestId)]: \(code): \(message)")
                    case .InternalServerError(let code, let message, let requestId):
                        print("InternalServerError[\(requestId)]: \(code): \(message)")
                    case .OSError(let err):
                        print("OSError: \(err)")
                    case .RateLimitError:
                        print("RateLimitError")
                    }
                }
        }
    }

    func uploadNextChunk() {
        data = fileHandle!.readDataOfLength(chunkSize)
        let size = data!.length
        print("Have \(size) bytes to upload.")
        if size &amp;lt; chunkSize {
            print("Last chunk!")
            Dropbox.authorizedClient!.files.uploadSessionFinish(
                cursor: Files.UploadSessionCursor(sessionId: self.sessionId, offset: UInt64(offset)),
                commit: Files.CommitInfo(path:destPath),
                input: data!)
                .response { response, error in
                    if let callError = error {
                        print("uploadSessionFinish failed")
                        switch callError as CallError {
                        case .RouteError(let boxed, let requestId):
                            print("RouteError[\(requestId)]:")
                            switch boxed.unboxed as Files.UploadSessionFinishError {
                            case .Path(let writeError):
                                print("Path: ")
                                switch writeError {
                                case .MalformedPath(let malformedPathError):
                                    print("MalformedPath: \(malformedPathError)")
                                case .Conflict(let writeConflictError):
                                    print("Conflict:")
                                    switch writeConflictError {
                                    case .File:
                                        print("File")
                                    case .FileAncestor:
                                        print("FileAncestor")
                                    case .Folder:
                                        print("Folder")
                                    case .Other:
                                        print("Other")
                                    }
                                case .DisallowedName:
                                    print("DisallowedName")
                                case .InsufficientSpace:
                                    print("InsufficientSpace")
                                case .NoWritePermission:
                                    print("NoWritePermission")
                                case .Other:
                                    print("Other")
                                }
                            case .LookupFailed(let uploadSessionLookupError):
                                print("LookupFailed:")
                                switch uploadSessionLookupError {
                                case .Closed:
                                    print("Closed")
                                case .IncorrectOffset(let uploadSessionOffsetError):
                                    print("IncorrectOffset: \(uploadSessionOffsetError)")
                                case .NotFound:
                                    print("NotFound")
                                case .NotClosed:
                                    print("NotFound")
                                case .Other:
                                    print("Other")
                                }
                            case .TooManySharedFolderTargets:
                                print("TooManySharedFolderTargets")
                            case .Other:
                                print("Other")
                            }
                        case .BadInputError(let message, let requestId):
                            print("BadInputError[\(requestId)]: \(message)")
                        case .HTTPError(let code, let message, let requestId):
                            print("HTTPError[\(requestId)]: \(code): \(message)")
                        case .InternalServerError(let code, let message, let requestId):
                            print("InternalServerError[\(requestId)]: \(code): \(message)")
                        case .OSError(let err):
                            print("OSError: \(err)")
                        case .RateLimitError:
                            print("RateLimitError")
                        }
                    } else if let result = response {
                        print("Done!")
                        print(result)
                    }
            }
        } else {
            Dropbox.authorizedClient!.files.uploadSessionAppendV2(
                cursor: Files.UploadSessionCursor(sessionId: self.sessionId, offset: UInt64(offset)),
                input: data!)
                .response { response, error in
                    if error == nil {
                        self.offset += self.chunkSize
                        print("So far \(self.offset) bytes have been uploaded.")
                        self.uploadNextChunk()
                    } else if let callError = error {
                        print("uploadSessionAppend failed")
                        switch callError as CallError {
                        case .RouteError(let boxed, let requestId):
                            print("RouteError[\(requestId)]:")
                            switch boxed.unboxed as Files.UploadSessionLookupError {
                            case .Closed:
                                print("Closed")
                            case .IncorrectOffset(let uploadSessionOffsetError):
                                print("IncorrectOffset: \(uploadSessionOffsetError)")
                            case .NotFound:
                                print("NotFound")
                            case .NotClosed:
                                print("NotClosed")
                            case .Other:
                                print("Other")
                            }
                        case .BadInputError(let message, let requestId):
                            print("BadInputError[\(requestId)]: \(message)")
                        case .HTTPError(let code, let message, let requestId):
                            print("HTTPError[\(requestId)]: \(code): \(message)")
                        case .InternalServerError(let code, let message, let requestId):
                            print("InternalServerError[\(requestId)]: \(code): \(message)")
                        case .OSError(let err):
                            print("OSError: \(err)")
                        case .RateLimitError:
                            print("RateLimitError")
                        }
                    }
            }
        }
    }

}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2017 15:35:34 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Uploading-a-file-to-Dropbox-in-chunks-using-Objective-C/m-p/251545#M14474</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2017-11-07T15:35:34Z</dc:date>
    </item>
  </channel>
</rss>

