Help us understand the problem. What is going on with this article?

SwiftyDropboxで150MB以上のファイルをUPLOADする

More than 3 years have passed since last update.

公式はサンプルを載せろ、と言いたい。

func uploadLargeFile(srcPath a_sSrcPath:String, dstPath a_sDstPath:String){

    if let client=Dropbox.authorizedClient{

        let inputStrm            = NSInputStream(fileAtPath: a_sSrcPath)
        inputStrm!.open()
        let sendBlockByte        = 1024 * 1024 * 50//50MB毎で
        var transferedCnt:UInt64 = 0
        var buffer               = Array<UInt8>(count:sendBlockByte, repeatedValue:0)
        var data                 = NSData.init(bytesNoCopy: &buffer, length:sendBlockByte, freeWhenDone:false)
        var sessionID            = ""
        var retryCnt             = 0



        var appendNextBlock:() -> Void = { () -> Void in }
        appendNextBlock = { () in

            let readCnt = inputStrm!.read(&buffer, maxLength: sendBlockByte)
            if (readCnt > 0) {
                if (readCnt != sendBlockByte) {
                    data = NSData.init(bytesNoCopy: &buffer, length:(readCnt >= 0 ? readCnt: 0), freeWhenDone:false)
                }

                var l_fncCompletion:((Void)?, CallError<(Files.UploadSessionLookupError)>?) -> Void = { (_, _) -> Void in }
                l_fncCompletion = { (response, error) in

                    debugPrint(response)

                    if error != nil {
                        // Lets Rety
                        retryCnt++
                        if (retryCnt < 4) {
                            client.files.uploadSessionAppend(sessionId:sessionID, offset:transferedCnt, body:data).response(l_fncCompletion)
                        }else{
                            debugPrint("ERROR")
                        }
                    }else{
                        transferedCnt = transferedCnt + UInt64(readCnt)
                        retryCnt = 0
                        appendNextBlock()
                    }
                }
                client.files.uploadSessionAppend(sessionId:sessionID, offset:transferedCnt, body:data).response(l_fncCompletion)
            }else{
                //全ブロック送信できたとき、finishする
                if (transferedCnt > 0) {
                    let sessionCursor = Files.UploadSessionCursor(sessionId: sessionID, offset: transferedCnt)
                    let commitInfo = Files.CommitInfo(path: a_sDstPath, mode: .Overwrite, autorename: false, clientModified: nil, mute: false)

                    client.files.uploadSessionFinish(cursor: sessionCursor, commit: commitInfo, body: NSData()).response( { (response, error) in


                        if let _ = response {
                            debugPrint("FINISH")
                        }else{
                            debugPrint("ERROR")
                        }
                    })
                }else{
                    debugPrint("ERROR")
                }
            }
        }

        //空のNSDataで始める
        let tmp = NSData()
        client.files.uploadSessionStart(body:tmp).response( {
            (response, errorType) -> Void in
            if let (startResult) = response {
                sessionID = startResult.sessionId
                appendNextBlock()
            }else{
                debugPrint("ERROR")
            }
        })

    }

}
nkmrtkhd
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした