We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Christian T.16
10 years agoNew member | Level 1
parsing upload session finish error
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.
...
Christian T.16
10 years agoNew member | Level 1
Here's my latest code. It seems like the append operations aren't being processed in the order they are called, so I'll get incorrect offset errors. For example, I had seven append calls, two succeeded, five failed.
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 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: NSData()).response { response, error in
if let result = response {
print("UPLOAD SESSION START RESULT: \(result)")
while (startPosition <= fileLength) {
startPosition = chunkLength*loopCounter
print("LOOP COUNTER: \(loopCounter)")
print("START POSITION: \(startPosition)")
if (startPosition+chunkLength >= UInt64(data.length)) {
print("FINAL START POSITION: \(startPosition)")
range = NSMakeRange(Int(startPosition), (data.length)-Int(startPosition))
print("FINAL RANGE: \(range)\n")
tempData = data.subdataWithRange(range)
client.files.uploadSessionAppend(sessionId: result.sessionId, offset: startPosition, body: tempData).response { response, error in
if let result = response {
print("FINAL APPEND RESULT: \(result)")
} else if let callError = error {
print("FINAL APPEND ERROR: \(error)")
}
}
break
}
range = NSMakeRange(Int(startPosition), Int(chunkLength))
print("RANGE: \(range)\n")
tempData = data.subdataWithRange(range)
client.files.uploadSessionAppend(sessionId: result.sessionId, offset: startPosition, body: tempData).response { response, error in
if let result = response {
print("APPEND RESULT: \(result)")
} else if let callError = error {
print("APPEND ERROR: \(error)")
}
}
loopCounter++
}
// 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!)")
}
}
}
}
Here's the console output....
FILE LENGTH: 33700300
CHUNK LENGTH: 5242880
MORE THAN CHUNK SIZE
UPLOAD SESSION START RESULT: {
"session_id" = "AAAAAAAAATQlmkMM-eETZA";
}
LOOP COUNTER: 0
START POSITION: 0
RANGE: (0,5242880)
LOOP COUNTER: 1
START POSITION: 5242880
RANGE: (5242880,5242880)
LOOP COUNTER: 2
START POSITION: 10485760
RANGE: (10485760,5242880)
LOOP COUNTER: 3
START POSITION: 15728640
RANGE: (15728640,5242880)
LOOP COUNTER: 4
START POSITION: 20971520
RANGE: (20971520,5242880)
LOOP COUNTER: 5
START POSITION: 26214400
RANGE: (26214400,5242880)
LOOP COUNTER: 6
START POSITION: 31457280
FINAL START POSITION: 31457280
FINAL RANGE: (31457280,2243020)
APPEND RESULT: ()
APPEND ERROR: Optional([request-id fb45a248b79b4989ff52163d957850d1] API route error - {
".tag" = "incorrect_offset";
"correct_offset" = 5242880;
})
APPEND ERROR: Optional([request-id 75490d1c812ef1072aef17269dda576d] API route error - {
".tag" = "incorrect_offset";
"correct_offset" = 5242880;
})
APPEND RESULT: ()
RouteError[Optional("054b4b3848a92df65a9f0cbcb580f3f8")]:
LookupFailed:
IncorrectOffset: {
"correct_offset" = 10485760;
}
FINAL APPEND ERROR: Optional([request-id 22682566e018e51de3b0d071d879f0a4] API route error - {
".tag" = "incorrect_offset";
"correct_offset" = 10485760;
})
APPEND ERROR: Optional([request-id c10a9f363552525ddea86a476cb5c921] API route error - {
".tag" = "incorrect_offset";
"correct_offset" = 10485760;
})
APPEND ERROR: Optional([request-id 587f7df38872cc7f3af9fa867646a5d0] API route error - {
".tag" = "incorrect_offset";
"correct_offset" = 10485760;
})
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!