Track Progress for Video Uploading on iOS with Rails Server -


i newbie ruby on rails , right building api uploading video rails server. have built uploading api carrierwave. going me. on ios side, need able track video uploading progress. need pro on rails give me advice on how on rails api or maybe on ios app. also, getting timeout on nsurlconnection while uploading video kind of problem me.

rails api code snippet

    data = params[:business_asset][:video].to_s     io = businessvideostring.new(base64.decode64(data))     io.original_filename = "foobar.mp4"     io.content_type = "video/mp4"     @business_asset.video = io      if @business_asset.save       render :json => { :video => @business.business_asset ,:message => "success"},:status => 200      end 

on ios side, using nsurlconnection methods

   - (void) postrequestfromurl: (nsstring *) urlstring withdictionary: (nsdictionary *) post{          nsurl *url = [nsurl urlwithstring:urlstring];         nserror *error;         nsdata *postdata = [nsjsonserialization datawithjsonobject:post options:0 error:&error];         nsstring *  postlength = [nsstring stringwithformat:@"%d", (int)[postdata length]];         nsmutableurlrequest * request = [[nsmutableurlrequest alloc] initwithurl:url];          //url u send data         [request sethttpmethod:@"post"];         [request setvalue:@"application/json" forhttpheaderfield:@"accept"];         [request setvalue:@"application/json" forhttpheaderfield:@"content-type"];         [request sethttpbody: postdata];         [request setvalue:[nsstring stringwithformat:@"%lu", (unsigned long)[postlength length]] forhttpheaderfield:@"content-length"];          nsurlconnection * conn = [[nsurlconnection alloc] initwithrequest:request delegate:self];         if(conn) {             nslog(@"connection successful");         } else {            nslog(@"connection not made");         }    } 

any advice on how should it?

thanks in advance.

you can send data , total data using following delegate,

- (void)connection:(nsurlconnection *)connection    didsendbodydata:(nsinteger)byteswritten  totalbyteswritten:(nsinteger)totalbyteswritten totalbytesexpectedtowrite:(nsinteger)totalbytesexpectedtowrite 

reference : https://developer.apple.com/library/mac/documentation/foundation/reference/nsurlconnectiondatadelegate_protocol/#//apple_ref/occ/intfm/nsurlconnectiondatadelegate/connection:didsendbodydata:totalbyteswritten:totalbytesexpectedtowrite:


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -