Posting video from ios time outs every time. video is of 6mb and 2.30 min


#1

using code as bellow
sudo code…

  Twitter.sharedInstance().logInWithCompletion { session, error in
                if (session != nil) {
                    
              let client = TWTRAPIClient(userID: session?.userID)
             let strUploadUrl = "https://upload.twitter.com/1.1/media/upload.json"
                    let strStatusUrl = "https://api.twitter.com/1.1/statuses/update.json"
                    UIApplication.sharedApplication().networkActivityIndicatorVisible = true
                    
                    var error: NSError?
                     var parameters:Dictionary = Dictionary<String, AnyObject>()
                   let videoData  =  NSData(contentsOfURL: self.videoURL!)
                   
                    do{
                        let fileAttributes = try NSFileManager.defaultManager().attributesOfItemAtPath(self.videoURL!.path!)
                        let fileSize = fileAttributes[NSFileSize]
                    print(fileSize)
                     parameters = [   "command" : "INIT", "media_type" : "video/mp4", "total_bytes" : "\(fileSize!)"]
                    
                }
                    catch let err as NSError{
                        //error handling
                    }
                    
            let asset : AVURLAsset = AVURLAsset(URL: self.videoURL!)
                    let duration : CMTime = asset.duration
                 let video = videoData!.base64EncodedStringWithOptions([])
             let twUploadRequest = client.URLRequestWithMethod("POST", 
 URL: strUploadUrl, 
            parameters:parameters, error: &error)
           
client.sendTwitterRequest(twUploadRequest) 
        {
              (uploadResponse, uploadResultData, uploadConnectionError) ->
   Void in
                        if (uploadConnectionError == nil) {
                            do {
                                let userinfo: AnyObject! = try       NSJSONSerialization.JSONObjectWithData(uploadResultData!, options:NSJSONReadingOptions(rawValue: 0))
                           
                                let collection = userinfo! as! Dictionary<String, AnyObject>
                                let mediaID : AnyObject = collection["media_id_string"] as! String
                                var error: NSError?
                                var parameters_Append:Dictionary = Dictionary<String, AnyObject>()
                                parameters_Append = [   "command" : "APPEND", "media_id" : mediaID, "media_data":video,"segment_index":"0" ]
                        let twStatusRequest = client.URLRequestWithMethod("POST", URL: strUploadUrl, parameters: parameters_Append, error: &error)
              client.sendTwitterRequest(twStatusRequest) { (uploadResponse, uploadResultData, uploadConnectionError) -> Void in
                                  
      var error: NSError?
      var parameters_Final:Dictionary = Dictionary<String, AnyObject>()
      parameters_Final = ["command":"FINALIZE", "media_id": mediaID]
                                  
        let twStatusRequest = client.URLRequestWithMethod("POST", URL: strUploadUrl, parameters: parameters_Final, error: &error)
                                    
     client.sendTwitterRequest(twStatusRequest) 

{ (uploadResponse, uploadResultData,         uploadConnectionError) -> Void in
       var parametersStat:Dictionary = Dictionary<String, AnyObject>()
    parametersStat = ["status": self.captionTextBox.text!, "wrap_links": "true", "media_ids": mediaID]
           
    let twStatusRequest = client.URLRequestWithMethod("POST",   
 URL: strStatusUrl,  
   parameters: parametersStat, error: &error)

                            
     client.sendTwitterRequest(twStatusRequest) 


          { (uploadResponse, uploadResultData, uploadConnectionError) -> 
        Void in

}
}


#2

Hey @k_mahadev7,

Thanks for reaching out on this and currently the video cannot be longer than 140 seconds or 2.20 minutes. There’s more information on the other requirements for upload here: https://dev.twitter.com/rest/media/uploading-media#videorecs

-Mike


#3

Thank you for your reply.
Now i have to use async video upload method, but unable to understand which method should i use to async call. Please Help @bonnell


#4

There should be sample calls that you can make under the section “Example of chunked video media/upload” in the same page I referenced earlier.
-Mike