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
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(")
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!