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, 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
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!