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: 

parsing upload session finish error

parsing upload session finish error

Christian T.16
New member | Level 1

Can you provide an example of how to parse an upload session finish error. Here's what I have but none of these cases are triggered. I do get Error but no further details. Thanks.

                        // we're ready to finish the upload and commit the file

                        client.files.uploadSessionFinish(cursor: Files.UploadSessionCursor(sessionId: result.sessionId, offset: position),

                            commit: Files.CommitInfo(path: “somePath”),

                            body:data).response { response, error in

                                

                                if let result = response {

                                    print("UPLOAD SESSION FINISH RESULT: \(result)")

                                } else {

                                    print("UPLOAD SESSION FINISH ERROR: \(error!)!")

                                    switch error {

                                        case .LookupFailed:

                                            print("LOOKUP FAILED")

                                        case .Path:

                                            print("PATH ERROR")

                                        case .Other:

                                            print("OTHER ERROR")

                                    }

                                }

 

                        }

 

17 Replies 17

Greg-DB
Dropbox Staff

What output do you get? Some errors are themselves unions, so be sure to break those out if you need.

For example, here's a sample breaking out every possible error case (with the latest version of SwiftyDropbox, v3.0.0):

// we're ready to finish the upload and commit the file
client.files.uploadSessionFinish(cursor: Files.UploadSessionCursor(sessionId: result.sessionId, offset: fileLength),
commit: Files.CommitInfo(path: "/test_swift_upload_session.txt"),
// no additional data to add at this point in this case
body:NSData()).response { response, error in
if let result = response {
print("Result: \(result)")
} else if let callError = error {
switch callError as CallError {
case .RouteError(let boxed, let requestId):
print("RouteError[\(requestId)]:")
switch boxed.unboxed as Files.UploadSessionFinishError {
case .Path(let fileLookupError):
print("Path: ")
switch fileLookupError {
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 .Other:
print("Other")
}
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")
}
}
}

Apologies for the poor formatting on the forum!

Christian T.16
New member | Level 1

cool, thanks, i'll give it a shot. I was getting an HTTP error.

Christian T.16
New member | Level 1

Thanks for working with me on this, but my HTTPError comes back as...

HTTPError[nil]: nil: Optional(")

Here's my code....


//trying to upload a 33MB file in 5MB chunks

let data:NSData = NSFileManager.defaultManager().contentsAtPath(path)!
let chunkLength:UInt64 = 1024 * 1024 * 5 //in MB
let fileLength:UInt64 = UInt64(data.length)

print("FILE LENGTH: \(fileLength)")
print("CHUNK LENGTH: \(chunkLength)")

if (fileLength < chunkLength) {
print("LESS THAN CHUNK SIZE")
//Upload File
if let client = Dropbox.authorizedClient {
client.files.upload(path:destinationPath+uploadFilename!, body:data).response { response, error in
if let metadata = response {
completion()
} else {
print("UPLOAD ERROR(DropboxUploader.swift): \(error!)")
}
}
}

} else {

print("MORE THAN CHUNK SIZE")

var inputStream:NSInputStream = NSInputStream(data: data)
var position:UInt64 = 0
var loopCounter:UInt64 = 0

//Upload File
if let client = Dropbox.authorizedClient {

client.files.uploadSessionStart(body: inputStream).response { response, error in

print("UPLOAD SESSION STARTED") 

if let result = response {

print("UPLOAD SESSION START RESULT: \(result)")

while (position <= fileLength) {

print("POSITION \(position)")

client.files.uploadSessionAppend(sessionId: result.sessionId, offset: position, body: inputStream)

loopCounter++
print("LOOPCOUNTER: \(loopCounter)")
position = chunkLength * loopCounter

if (position >= UInt64(data.length)) {

position = UInt64(data.length)
print("POSITION \(position)")

client.files.uploadSessionAppend(sessionId: result.sessionId, offset: position, body: inputStream)

break
}

}


// we're ready to finish the upload and commit the file
client.files.uploadSessionFinish(cursor: Files.UploadSessionCursor(sessionId: result.sessionId, offset: position),
commit: Files.CommitInfo(path: destinationPath+uploadFilename!),
// no additional data to add at this point in this case
body:NSData()).response { response, error in

if let result = response {
print("Result: \(result)")
} else if let callError = error {
switch callError as CallError {
case .RouteError(let boxed, let requestId):
print("RouteError[\(requestId)]:")
switch boxed.unboxed as Files.UploadSessionFinishError {
case .Path(let fileLookupError):
print("Path: ")
switch fileLookupError {
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 .Other:
print("Other")
}
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 {
print("UPLOAD SESSION START ERROR(DropboxUploader.swift): \(error!)")
}
}
}
}

 

Here's the console output...

FILE LENGTH: 33700300

CHUNK LENGTH: 5242880

MORE THAN CHUNK SIZE

UPLOAD SESSION STARTED

UPLOAD SESSION START RESULT: {

    "session_id" = "AAAAAAAAAK-OwgQJFJJj8g";

}

POSITION 0

LOOPCOUNTER: 1

POSITION 5242880

LOOPCOUNTER: 2

POSITION 10485760

LOOPCOUNTER: 3

POSITION 15728640

LOOPCOUNTER: 4

POSITION 20971520

LOOPCOUNTER: 5

POSITION 26214400

LOOPCOUNTER: 6

POSITION 31457280

LOOPCOUNTER: 7

POSITION 33700300

HTTPError[nil]: nil: Optional(")

Greg-DB
Dropbox Staff

Thanks for the code Christian! Two things occur to me:

- It looks like you're passing in the entire inputStream object with each call. You should only pass in a chunk of data for each.

- You're not checking the response/error on your append calls. Make sure to do so to see if it's failing earlier there.

Christian T.16
New member | Level 1

Thanks, so now i'm chunking up my file and upload is successful for files 200MB or less but now I get a memory warnings for anything bigger. Am I suppose to send the first chunk with sessionStart, and the last chunk with sessionFinish? Or should the start and finish have empty body data and append all the chunks through append? Thanks, here's the updated code...

//Successfully uploaded file up to 210MB file in 5MB chunks

       let chunkLength:UInt64 = 1024 * 1024 * 5 //in MB

        let fileLength:UInt64 = UInt64(data.length)//Double(data.length)/1024/1024 //in MB

        

        print("FILE LENGTH: \(fileLength)")

        print("CHUNK LENGTH: \(chunkLength)")

        

        if (fileLength < chunkLength) {

            print("LESS THAN CHUNK SIZE")

            //Upload File

            if let client = Dropbox.authorizedClient {

                client.files.upload(path:destinationPath+uploadFilename!, body:data).response { response, error in

                    if let metadata = response {

                        completion()

                    } else {

                        print("UPLOAD ERROR(DropboxUploader.swift): \(error!)")

                    }

                }

            }

            

        } else {

            

            print("MORE THAN CHUNK SIZE")

            

            var inputStream:NSInputStream = NSInputStream(data: data)

            var startPosition:UInt64 = 0

            var loopCounter:UInt64 = 0

            var tempData:NSData = data

            var range:NSRange = NSMakeRange(Int(startPosition), Int(chunkLength))

            

            //Upload File

            if let client = Dropbox.authorizedClient {   

                client.files.uploadSessionStart(body: inputStream).response { response, error in                    

                    print("UPLOAD SESSION STARTED")

                    if let result = response {

                        print("UPLOAD SESSION START RESULT: \(result)")

                        while (startPosition <= fileLength) {

                            

                            startPosition = chunkLength*loopCounter

                            

                            if (startPosition+chunkLength >= UInt64(data.length)) {

                                

                                print("START POSITION \(startPosition)")

                                

                                range = NSMakeRange(Int(startPosition), (data.length)-Int(startPosition))

                                tempData = data.subdataWithRange(range)

                                

                                client.files.uploadSessionAppend(sessionId: result.sessionId, offset: startPosition, body: tempData)

                                

                                break

                            }

                            

                            print("START POSITION \(startPosition)")

                            

                            range = NSMakeRange(Int(startPosition), Int(chunkLength))

                            tempData = data.subdataWithRange(range)

                        

                            client.files.uploadSessionAppend(sessionId: result.sessionId, offset: startPosition, body: tempData)

                            

                            loopCounter++

                            print("LOOPCOUNTER: \(loopCounter)")

                            

 

                        }

 

                        startPosition = UInt64(data.length)

                        print("START POSITION \(startPosition)")

                        

                        // we're ready to finish the upload and commit the file

                        client.files.uploadSessionFinish(cursor: Files.UploadSessionCursor(sessionId: result.sessionId, offset: startPosition),

                            commit: Files.CommitInfo(path: destinationPath+uploadFilename!),

                            // no additional data to add at this point in this case

                            body:NSData()).response { response, error in

                                

                                if let result = response {

                                    print("Result: \(result)")

                                } else if let callError = error {

                                    switch callError as CallError {

                                    case .RouteError(let boxed, let requestId):

                                        print("RouteError[\(requestId)]:")

                                        switch boxed.unboxed as Files.UploadSessionFinishError {

                                        case .Path(let fileLookupError):

                                            print("Path: ")

                                            switch fileLookupError {

                                            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 .Other:

                                                print("Other")

                                            }

                                        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 {

                        print("UPLOAD SESSION START ERROR(DropboxUploader.swift): \(error!)")

                    }

                }

            }

        }

 

UPDATE: I changed the following line from inputStream to NSData which gets me past the Memory Warning but now I get HTTP Error code: nil message: nil for files larger than 200MB.

client.files.uploadSessionStart(body: inputStream).response { response, error in

Greg-DB
Dropbox Staff

You should only upload one chunkLength's worth of data with each call. The following line seems to indicate that you're uploading much more than that for each though:

range = NSMakeRange(Int(startPosition), (data.length)-Int(startPosition))

I.e., the end of the range should probably be something like startPosition + chunkLength.

Anyway, each of the three calls have the ability to take a chunk of data, but it's not required that you do supply data to each. You just need to make sure you upload all of the chunks in order.

Also, it looks like you're still not checking the response on uploadSessionAppend. You should implement the .response callback on that just like the other calls.

Christian T.16
New member | Level 1

I'm getting successful append results...but the uploadSessionFinish keeps throwing an HTTPError. Do I need to do any memory management with how many appends I can do during a session?

                            client.files.uploadSessionAppend(sessionId: result.sessionId, offset: startPosition, body: tempData).response { reponse, error in

                                

                                if let result = response {

                                    print("APPEND RESPONSE: \(response)")

                                } else {

                                    print("APPEND ERROR: \(error)")

                                }

                            }

APPEND RESPONSE: Optional({

    "session_id" = AAAAAAAAAQvvYtd4WDV66A;

})

APPEND RESPONSE: Optional({

    "session_id" = AAAAAAAAAQvvYtd4WDV66A;

})

APPEND RESPONSE: Optional({

    "session_id" = AAAAAAAAAQvvYtd4WDV66A;

})

HTTPError[nil]: nil: Optional(")

 

With this line...

range = NSMakeRange(Int(startPosition), (data.length)-Int(startPosition))

...the final append is simply whatever is left of the file to upload.

Greg-DB
Dropbox Staff

Can you share your latest code? That line still looks problematic. The intent of upload sessions is that you would only ever send up a maximum of one chunk size's worth of data in a single call, but you seem to indicate that you're sending up the entire rest of the file. For a 210 MB file, using 5 MB chunks, it should take a total of 42 calls.

Christian T.16
New member | Level 1

Before I share my latest code, let me make sure I understand the offset. It says...

offset

The amount of data that has been uploaded so far. We use this to make sure upload data isn’t lost or duplicated in the event of a network error.

Does this mean the amount of data uploaded in previous call(s)? (i.e., does not include the current call's body data)?

So, for my first upload call my offset should be 0 since no data has been upload so far.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Christian T.16 New member | Level 1
  • User avatar
    Steve M. Dropbox Staff
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?