objective c - Retrieving images once saved to a server -


i have code written uploads image server, not sure how retrieve images after upload them. tried using nsurl request, did receivedata delegate method never called. below i've included relevant code related uploading picture, , attempt @ pulling data using nsurl request. there conceptually i'm doing wrong? thank you.

- (ibaction)nextbuttonpressed:(id)sender { [self.signupcontroller uploadprofilepicture:uiimagepngrepresentation(self.imageview.image) completion:^(nserror *error){     [[nsoperationqueue mainqueue] addoperationwithblock:^{         [[synccontroller sharedinstance] sync];         [self performseguewithidentifier:@"addfriendssegue" sender:self];     }]; }]; } 

and uploadprofilepicture method:

- (void)uploadprofilepicture:(nsdata *)imagedata completion:(void (^)(nserror *error))completion { bruser *user = [brsession userwithcontext:[[brcoredatamanager sharedmanager] maincontext]]; [self.apiclient uploadprofilepicture:imagedata foruser:user parameters:nil completion:[self uploadprofilepicturehandlerwithcompletion:completion]]; } 

and then, also, here upload profile picture method in api client:

- (void)uploadprofilepicture:(nsdata *)imagedata foruser:(bruser *)user parameters:(nsdictionary *)parameters completion:(brapiclientcompletionblock)completion { nserror *error; nsurlrequest *request = [self.requestserializer multiformrequestforapiaction:brapiactioncreate nestedresource:@"image" parent:user data:imagedata parameters:parameters error:&error]; if (error) {     completion(nil, error); } nsurlsessiondatataskcompletionblock datataskcompletion = [self requesthandlerwithhttpstatuserrors:@{ @400 : @(brapiunauthorized) }  completion:completion]; nsurlsessiondatatask *task = [self.authurlsession datataskwithrequest:request completionhandler:datataskcompletion]; [task resume]; } 

and multiform method called in previous method:

- (nsurlrequest *)multiformrequestforapiaction:(brapiaction)action nestedresource:(id)resource parent:(id)parent data:(nsdata *)data parameters:(nsdictionary *)parameters error:(nserror *__autoreleasing *)error { nsparameterassert(action); nsparameterassert(resource); nsparameterassert(parent); nsparameterassert(data);  nsstring *method = [brapirequestserializer httpmethodforapiaction:action]; nsurl *url = [self.apiurl nestedurlforresource:resource parent:parent]; nslog(@"url: %@",[url absolutestringwithtrailingslash]);  return [self.serializer multipartformrequestwithmethod:method                                              urlstring:[url absolutestringwithtrailingslash]                                             parameters:parameters                              constructingbodywithblock:^(id<afmultipartformdata> formdata) {                                  [formdata appendpartwithfiledata:data name:@"image" filename:@"image.png" mimetype:@"image/png"];                              }                                                  error:error]; } 

and failed attempt @ retrieving data via url it's stored at:

-(void) downloadimagefromurl :(nsstring *)imageurlstring{ // create request. nsurlrequest *therequest=[nsurlrequest requestwithurl:[nsurl urlwithstring:imageurlstring]                                           cachepolicy:nsurlrequestuseprotocolcachepolicy                                       timeoutinterval:60.0];  // create nsmutabledata hold received data. // receiveddata instance variable declared elsewhere. nsdata * receiveddata = [[nsmutabledata alloc] init];  // create connection request // , start loading data nsurlconnection *theconnection=[[nsurlconnection alloc] initwithrequest:therequest delegate:self]; if (!theconnection) {     // release receiveddata object.     receiveddata = nil;      // inform user connection failed.     nslog(@"connection falied"); } else {     nslog(@"connection succesful"); }; 

}

- (void)connection:(nsurlconnection *)connection didreceivedata:(nsdata *)data {      nslog(@"data: %@",data); } 

i made sure include nsurlconnectiondelegate. didrecievedata method never called.

feel free let me know if there's more code need see!


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -