We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
Forum Discussion
RTS S.
10 years agoHelpful | Level 6
Swift API v2 Example of uploading a file using filesUploadSession(Start, Append, Finish)
I have used the OSX interface in the past for chunked file uploads to support large files. I can not quite figure out the process with the Swift API.
Test cases for the API would be great, they wo...
Greg-DB
10 years agoDropbox Staff
I don't think we have a full sample using that published, but here's a very simple example I just put together: (apologies for the atrocious code formatting on the forum)
// Write a file to the local documents directory
let text = "Hello world. Usually something much longer here."
let filename = "working-draft.txt"
let localDir = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let localPath = localDir.stringByAppendingString(filename)
try! text.writeToFile(localPath, atomically:true, encoding:NSUTF8StringEncoding)
let fileURL = NSURL.fileURLWithPath(localPath)
let fileLength = UInt64(text.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
print(fileURL)
print(fileLength)
// start the upload session, passing along the NSURL to the whole file in this case, since it's small
// there are also versions that take NSData or NSInputStream as the body
client.filesUploadSessionStart(body: fileURL).response { response, error in
if let result = response {
// the call succeeded
print(result)
// also call filesUploadSessionAppend to add more data if/as necessary, as many times as necessary (be sure to track the offset)
// we're ready to finish the upload and commit the file
client.filesUploadSessionFinish(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)
} else {
print(error!)
}
}
} else {
// the call failed
print(error!)
}
}
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,877 PostsLatest Activity: 12 months agoIf 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 or Facebook.
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!